@@ -47,7 +47,7 @@ |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | // Build DROP PARTITION statement |
50 | - $partitionNames = implode(', ', array_map(function ($partition) { |
|
50 | + $partitionNames = implode(', ', array_map(function($partition) { |
|
51 | 51 | return $partition->PARTITION_NAME; |
52 | 52 | }, $partitions)); |
53 | 53 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | if (Schema::hasTable('cache_invalidation_event_associations')) { |
15 | 15 | return; |
16 | 16 | } |
17 | - Schema::create('cache_invalidation_event_associations', function (Blueprint $table) { |
|
17 | + Schema::create('cache_invalidation_event_associations', function(Blueprint $table) { |
|
18 | 18 | //$table->bigIncrements('id'); |
19 | 19 | $table->bigInteger('id')->unsigned(); // Definiamo l'ID come bigInteger senza autoincrement sennò la primarykey multipla non funziona |
20 | 20 | $table->unsignedBigInteger('event_id')->comment('Reference to cache_invalidation_events.id'); |
@@ -14,7 +14,7 @@ |
||
14 | 14 | if (Schema::hasTable('cache_invalidation_timestamps')) { |
15 | 15 | return; |
16 | 16 | } |
17 | - Schema::create('cache_invalidation_timestamps', function (Blueprint $table) { |
|
17 | + Schema::create('cache_invalidation_timestamps', function(Blueprint $table) { |
|
18 | 18 | $table->enum('identifier_type', ['key', 'tag'])->comment('Indicates whether the identifier is a cache key or tag'); |
19 | 19 | $table->string('identifier')->comment('The cache key or tag'); |
20 | 20 | $table->dateTime('last_invalidated')->comment('Timestamp of the last invalidation'); |
@@ -16,16 +16,16 @@ discard block |
||
16 | 16 | { |
17 | 17 | // Merge package configuration |
18 | 18 | $this->mergeConfigFrom( |
19 | - __DIR__ . '/../config/super_cache_invalidate.php', |
|
19 | + __DIR__.'/../config/super_cache_invalidate.php', |
|
20 | 20 | 'super_cache_invalidate' |
21 | 21 | ); |
22 | 22 | |
23 | 23 | // Register the helper as a singleton |
24 | - $this->app->singleton(SuperCacheInvalidationHelper::class, function () { |
|
24 | + $this->app->singleton(SuperCacheInvalidationHelper::class, function() { |
|
25 | 25 | return new SuperCacheInvalidationHelper(); |
26 | 26 | }); |
27 | 27 | |
28 | - $this->app->singleton('super_cache_invalidate', function () { |
|
28 | + $this->app->singleton('super_cache_invalidate', function() { |
|
29 | 29 | return new SuperCacheInvalidationHelper(); |
30 | 30 | }); |
31 | 31 | } |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | { |
38 | 38 | // Publish configuration |
39 | 39 | $this->publishes([ |
40 | - __DIR__ . '/../config/super_cache_invalidate.php' => config_path('super_cache_invalidate.php'), |
|
40 | + __DIR__.'/../config/super_cache_invalidate.php' => config_path('super_cache_invalidate.php'), |
|
41 | 41 | ], 'config'); |
42 | 42 | |
43 | 43 | // Publish migrations |
44 | - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
|
44 | + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
|
45 | 45 | // Register commands |
46 | 46 | if ($this->app->runningInConsole()) { |
47 | 47 | $this->commands([ |
@@ -61,7 +61,7 @@ |
||
61 | 61 | // Per i siti in cui l'ho già creata (lvr, Santha, Pissei) la ricreo con le partizioni giuste |
62 | 62 | Schema::dropIfExists('cache_invalidation_events'); |
63 | 63 | |
64 | - Schema::create('cache_invalidation_events', function (Blueprint $table) { |
|
64 | + Schema::create('cache_invalidation_events', function(Blueprint $table) { |
|
65 | 65 | //$table->bigIncrements('id'); |
66 | 66 | $table->bigInteger('id')->unsigned(); // Definiamo l'ID come bigInteger senza autoincrement sennò la primarykey multipla non funziona |
67 | 67 | $table->enum('type', ['key', 'tag'])->comment('Indicates whether the event is for a cache key or tag'); |
@@ -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); |
@@ -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); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | // oppure di default uso Laravel |
208 | - $storeName = $this->getStoreFromConnectionName($connection_name); |
|
208 | + $storeName = $this->getStoreFromConnectionName($connection_name); |
|
209 | 209 | |
210 | 210 | if ($storeName === null) { |
211 | 211 | continue; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | return; |
243 | 243 | } |
244 | 244 | foreach ($groupByConnection as $connection_name => $arrTags) { |
245 | - $storeName = $this->getStoreFromConnectionName($connection_name); |
|
245 | + $storeName = $this->getStoreFromConnectionName($connection_name); |
|
246 | 246 | if ($storeName === null) { |
247 | 247 | continue; |
248 | 248 | } |
@@ -263,13 +263,13 @@ discard block |
||
263 | 263 | $tagBatchSize = $this->option('tag-batch-size') ?? config('super_cache_invalidate.tag_batch_size'); |
264 | 264 | $this->tagBatchSize = (int) $tagBatchSize; |
265 | 265 | $this->connection_name = $this->option('connection_name') ?? config('super_cache_invalidate.default_connection_name'); |
266 | - $this->log_attivo = $this->option('log_attivo') && (int)$this->option('log_attivo') === 1; |
|
266 | + $this->log_attivo = $this->option('log_attivo') && (int) $this->option('log_attivo') === 1; |
|
267 | 267 | $this->invalidation_window = (int) config('super_cache_invalidate.invalidation_window'); |
268 | 268 | $lockTimeout = (int) config('super_cache_invalidate.lock_timeout'); |
269 | 269 | |
270 | 270 | // Acquisisco il lock in modo da essere sicura che le esecuzioni non si accavallino |
271 | 271 | // $lockValue = $this->helper->acquireShardLock($this->shardId, $this->priority, $lockTimeout, $this->connection_name); |
272 | - $this->logIf('Starting Elaborazione ...' . $this->invalidation_window); |
|
272 | + $this->logIf('Starting Elaborazione ...'.$this->invalidation_window); |
|
273 | 273 | // if (!$lockValue) { |
274 | 274 | // return; |
275 | 275 | // } |
@@ -286,6 +286,6 @@ discard block |
||
286 | 286 | ), 'error'); |
287 | 287 | } |
288 | 288 | $executionTime = (microtime(true) - $startTime) * 1000; |
289 | - $this->logIf('Fine Elaborazione - Tempo di esecuzione: ' . $executionTime . ' millisec.'); |
|
289 | + $this->logIf('Fine Elaborazione - Tempo di esecuzione: '.$executionTime.' millisec.'); |
|
290 | 290 | } |
291 | 291 | } |
@@ -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()->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 | } |