@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | } catch (\Throwable $e) { |
94 | 94 | // DB::rollBack(); // Annulla la transazione in caso di errore |
95 | 95 | $attempts++; |
96 | - Log::error("SuperCacheInvalidate: impossibile eseguire insert, tentativo $attempts di $maxAttempts: " . $e->getMessage()); |
|
96 | + Log::error("SuperCacheInvalidate: impossibile eseguire insert, tentativo $attempts di $maxAttempts: ".$e->getMessage()); |
|
97 | 97 | // Logica per gestire i tentativi falliti |
98 | 98 | if ($attempts >= $maxAttempts) { |
99 | 99 | // Salta il record dopo il numero massimo di tentativi |
100 | - Log::error("SuperCacheInvalidate: impossibile eseguire insert dopo $maxAttempts tentativi: " . $e->getMessage()); |
|
100 | + Log::error("SuperCacheInvalidate: impossibile eseguire insert dopo $maxAttempts tentativi: ".$e->getMessage()); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @param string $connection_name The Redis Connection name |
112 | 112 | * @return string|false The lock value if acquired, false otherwise |
113 | 113 | */ |
114 | - public function acquireShardLock(int $shardId, int $priority, int $lockTimeout, string $connection_name): bool|string |
|
114 | + public function acquireShardLock(int $shardId, int $priority, int $lockTimeout, string $connection_name): bool | string |
|
115 | 115 | { |
116 | - $lockKey = 'shard_lock:' . $shardId . '_' . $priority; |
|
116 | + $lockKey = 'shard_lock:'.$shardId.'_'.$priority; |
|
117 | 117 | // Il metodo has/exists occupa troppa memoria!!! |
118 | 118 | $retrieveValue = Redis::connection($connection_name)->get($lockKey); |
119 | 119 | if ($retrieveValue !== null) { |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function releaseShardLock(int $shardId, int $priority, string $lockValue, string $connection_name): void |
141 | 141 | { |
142 | - $lockKey = 'shard_lock:' . $shardId . '_' . $priority; |
|
142 | + $lockKey = 'shard_lock:'.$shardId.'_'.$priority; |
|
143 | 143 | $currentValue = Redis::connection($connection_name)->get($lockKey); |
144 | 144 | if ($currentValue === $lockValue) { |
145 | 145 | Redis::connection($connection_name)->del($lockKey); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | return; |
12 | 12 | } |
13 | 13 | |
14 | - Schema::table('cache_invalidation_events', function (Blueprint $table) { |
|
14 | + Schema::table('cache_invalidation_events', function(Blueprint $table) { |
|
15 | 15 | $table->char('batch_ID', 36)->nullable()->index()->after('id'); |
16 | 16 | }); |
17 | 17 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | if (!Schema::hasColumn('cache_invalidation_events', 'batch_ID')) { |
25 | 25 | return; |
26 | 26 | } |
27 | - Schema::table('cache_invalidation_events', function (Blueprint $table) { |
|
27 | + Schema::table('cache_invalidation_events', function(Blueprint $table) { |
|
28 | 28 | $table->dropColumn('batch_ID'); |
29 | 29 | }); |
30 | 30 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | if (!$this->log_attivo && $level === 'info') { |
76 | 76 | return; |
77 | 77 | } |
78 | - $this->$level(now()->toDateTimeString() . ' Shard[' . $this->shardId . '] Priority[' . $this->priority . '] Connection[' . $this->connection_name . '] : ' . PHP_EOL . $message); |
|
78 | + $this->$level(now()->toDateTimeString().' Shard['.$this->shardId.'] Priority['.$this->priority.'] Connection['.$this->connection_name.'] : '.PHP_EOL.$message); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | protected function processEvents(): void |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $processingStartTime = now(); |
84 | 84 | // Recupero gli eventi da invalidare |
85 | 85 | $events = $this->getEventsToInvalidate($processingStartTime); |
86 | - $this->logIf('Trovati ' . count($events) . ' Eventi da invalidare'); |
|
86 | + $this->logIf('Trovati '.count($events).' Eventi da invalidare'); |
|
87 | 87 | if (count($events) === 0) { |
88 | 88 | return; |
89 | 89 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $unique_events = []; |
93 | 93 | |
94 | 94 | foreach ($events as $event) { |
95 | - $key = $event->type . ':' . $event->identifier; // Chiave univoca per type + identifier |
|
95 | + $key = $event->type.':'.$event->identifier; // Chiave univoca per type + identifier |
|
96 | 96 | $event->event_time = \Illuminate\Support\Carbon::parse($event->event_time); |
97 | 97 | // Quando la chiave non esiste o il nuovo valore ha un event_time più vecchio, lo sostituisco così a parità di tag ho sempre quello più vecchio e mi baso su quello per verificare la finestra |
98 | 98 | if (!isset($unique_events[$key]) || $event->event_time <= $unique_events[$key]->event_time) { |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | |
103 | 103 | $unique_events = array_values($unique_events); |
104 | 104 | |
105 | - $this->logIf('Eventi unici ' . count($unique_events)); |
|
105 | + $this->logIf('Eventi unici '.count($unique_events)); |
|
106 | 106 | // Quando il numero di eventi unici è inferiore al batchSize e quello più vecchio aspetta da almeno due minuti, mando l'invalidazione. |
107 | 107 | // Questo serve per i siti piccoli che hanno pochi eventi, altrimenti si rischia di attendere troppo per invalidare i tags |
108 | 108 | // In questo caso invalido i tag/key "unici" e setto a processed = 1 tutti quelli recuperati |
109 | 109 | if (count($unique_events) < $this->tagBatchSize && $processingStartTime->diffInSeconds($unique_events[0]->event_time) >= 120) { |
110 | - $this->logIf('Il numero di eventi unici è inferiore al batchSize ( ' . $this->tagBatchSize . ' ) e sono passati più di due minuti, procedo'); |
|
110 | + $this->logIf('Il numero di eventi unici è inferiore al batchSize ( '.$this->tagBatchSize.' ) e sono passati più di due minuti, procedo'); |
|
111 | 111 | $this->processBatch($events, $unique_events); |
112 | 112 | |
113 | 113 | return; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | // altrimenti aggiungo l'evento a quelli da processare |
128 | 128 | $eventsToUpdate[] = $event; |
129 | 129 | // e recupero tutti gli ID che hanno quel tag/key |
130 | - $eventsAll[] = array_filter($events, function ($event) use ($typeFilter, $identifierFilter) { |
|
130 | + $eventsAll[] = array_filter($events, function($event) use ($typeFilter, $identifierFilter) { |
|
131 | 131 | return $event->type === $typeFilter && $event->identifier === $identifierFilter; |
132 | 132 | }); |
133 | 133 | } |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | foreach ($eventsToInvalidate as $item) { |
150 | 150 | switch ($item->type) { |
151 | 151 | case 'key': |
152 | - $keys[] = $item->identifier . '§' . $item->connection_name; |
|
152 | + $keys[] = $item->identifier.'§'.$item->connection_name; |
|
153 | 153 | break; |
154 | 154 | case 'tag': |
155 | - $tags[] = $item->identifier . '§' . $item->connection_name; |
|
155 | + $tags[] = $item->identifier.'§'.$item->connection_name; |
|
156 | 156 | break; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - $this->logIf('Invalido ' . count($keys) . ' chiavi e ' . count($tags) . ' tags' . ' per un totale di ' . count($allEvents) . ' events_ID'); |
|
160 | + $this->logIf('Invalido '.count($keys).' chiavi e '.count($tags).' tags'.' per un totale di '.count($allEvents).' events_ID'); |
|
161 | 161 | |
162 | 162 | if (!empty($keys)) { |
163 | 163 | $this->invalidateKeys($keys); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | DB::statement('SET UNIQUE_CHECKS=1;'); |
184 | 184 | |
185 | 185 | // A questo punto avviso il gescat che le chiavi/tags sono stati puliti, per cui può procedere alla pulizia della CDN |
186 | - ds("lancio evento: " . $batch_ID); |
|
186 | + ds("lancio evento: ".$batch_ID); |
|
187 | 187 | event(new BatchCompletedEvent($batch_ID, $this->shardId)); |
188 | 188 | } |
189 | 189 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | // oppure di default uso Laravel |
209 | - $storeName = $this->getStoreFromConnectionName($connection_name); |
|
209 | + $storeName = $this->getStoreFromConnectionName($connection_name); |
|
210 | 210 | |
211 | 211 | if ($storeName === null) { |
212 | 212 | continue; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | return; |
244 | 244 | } |
245 | 245 | foreach ($groupByConnection as $connection_name => $arrTags) { |
246 | - $storeName = $this->getStoreFromConnectionName($connection_name); |
|
246 | + $storeName = $this->getStoreFromConnectionName($connection_name); |
|
247 | 247 | if ($storeName === null) { |
248 | 248 | continue; |
249 | 249 | } |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | $tagBatchSize = $this->option('tag-batch-size') ?? config('super_cache_invalidate.tag_batch_size'); |
265 | 265 | $this->tagBatchSize = (int) $tagBatchSize; |
266 | 266 | $this->connection_name = $this->option('connection_name') ?? config('super_cache_invalidate.default_connection_name'); |
267 | - $this->log_attivo = $this->option('log_attivo') && (int)$this->option('log_attivo') === 1; |
|
267 | + $this->log_attivo = $this->option('log_attivo') && (int) $this->option('log_attivo') === 1; |
|
268 | 268 | $this->invalidation_window = (int) config('super_cache_invalidate.invalidation_window'); |
269 | 269 | $lockTimeout = (int) config('super_cache_invalidate.lock_timeout'); |
270 | 270 | |
271 | 271 | // Acquisisco il lock in modo da essere sicura che le esecuzioni non si accavallino |
272 | 272 | // $lockValue = $this->helper->acquireShardLock($this->shardId, $this->priority, $lockTimeout, $this->connection_name); |
273 | - $this->logIf('Starting Elaborazione ...' . $this->invalidation_window); |
|
273 | + $this->logIf('Starting Elaborazione ...'.$this->invalidation_window); |
|
274 | 274 | // if (!$lockValue) { |
275 | 275 | // return; |
276 | 276 | // } |
@@ -287,6 +287,6 @@ discard block |
||
287 | 287 | ), 'error'); |
288 | 288 | } |
289 | 289 | $executionTime = (microtime(true) - $startTime) * 1000; |
290 | - $this->logIf('Fine Elaborazione - Tempo di esecuzione: ' . $executionTime . ' millisec.'); |
|
290 | + $this->logIf('Fine Elaborazione - Tempo di esecuzione: '.$executionTime.' millisec.'); |
|
291 | 291 | } |
292 | 292 | } |