Passed
Push — main ( 3a545a...8be070 )
by
unknown
10:00
created
src/Console/PruneCacheInvalidationDataCommand.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
2024_11_20_200802_create_cache_invalidation_event_associations_table.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
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');
Please login to merge, or discard this patch.
migrations/2024_11_20_200801_create_cache_invalidation_timestamps_table.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
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');
Please login to merge, or discard this patch.
src/SuperCacheInvalidateServiceProvider.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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([
Please login to merge, or discard this patch.
src/Helpers/SuperCacheInvalidationHelper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
             } catch (\Throwable $e) {
80 80
                 //DB::rollBack(); // Annulla la transazione in caso di errore
81 81
                 $attempts++;
82
-                Log::error("SuperCacheInvalidate: impossibile eseguire insert, tentativo $attempts di $maxAttempts: " . $e->getMessage());
82
+                Log::error("SuperCacheInvalidate: impossibile eseguire insert, tentativo $attempts di $maxAttempts: ".$e->getMessage());
83 83
                 // Logica per gestire i tentativi falliti
84 84
                 if ($attempts >= $maxAttempts) {
85 85
                     // Salta il record dopo il numero massimo di tentativi
86
-                    Log::error("SuperCacheInvalidate: impossibile eseguire insert dopo $maxAttempts tentativi: " . $e->getMessage());
86
+                    Log::error("SuperCacheInvalidate: impossibile eseguire insert dopo $maxAttempts tentativi: ".$e->getMessage());
87 87
                 }
88 88
             }
89 89
         }
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
      * @param  string       $connection_name The Redis Connection name
98 98
      * @return string|false The lock value if acquired, false otherwise
99 99
      */
100
-    public function acquireShardLock(int $shardId, int $priority, int $lockTimeout, string $connection_name): bool|string
100
+    public function acquireShardLock(int $shardId, int $priority, int $lockTimeout, string $connection_name): bool | string
101 101
     {
102
-        $lockKey = 'shard_lock:' . $shardId . '_' . $priority;
102
+        $lockKey = 'shard_lock:'.$shardId.'_'.$priority;
103 103
         // Il metodo has/exists occupa troppa memoria!!!
104 104
         $retrieveValue = Redis::connection($connection_name)->get($lockKey);
105 105
         if ($retrieveValue !== null) {
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      */
126 126
     public function releaseShardLock(int $shardId, int $priority, string $lockValue, string $connection_name): void
127 127
     {
128
-        $lockKey = 'shard_lock:' . $shardId . '_' . $priority;
128
+        $lockKey = 'shard_lock:'.$shardId.'_'.$priority;
129 129
         $currentValue = Redis::connection($connection_name)->get($lockKey);
130 130
         if ($currentValue === $lockValue) {
131 131
             Redis::connection($connection_name)->del($lockKey);
Please login to merge, or discard this patch.
migrations/2025_01_08_400999_create_cache_invalidation_events_table.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
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');
Please login to merge, or discard this patch.
src/Console/ProcessCacheInvalidationEventsCommand.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         if (!$this->log_attivo && $level === 'info') {
73 73
             return;
74 74
         }
75
-        $this->$level(now()->toDateTimeString() . ' Shard[' . $this->shardId . '] Priority[' . $this->priority . '] Connection[' . $this->connection_name . '] : ' . PHP_EOL . $message);
75
+        $this->$level(now()->toDateTimeString().' Shard['.$this->shardId.'] Priority['.$this->priority.'] Connection['.$this->connection_name.'] : '.PHP_EOL.$message);
76 76
     }
77 77
 
78 78
     protected function processEvents(): void
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $processingStartTime = now();
81 81
         // Recupero gli eventi da invalidare
82 82
         $events = $this->getEventsToInvalidate($processingStartTime);
83
-        $this->logIf('Trovati ' . count($events) . ' Eventi da invalidare');
83
+        $this->logIf('Trovati '.count($events).' Eventi da invalidare');
84 84
         if (count($events) === 0) {
85 85
             return;
86 86
         }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         $unique_events = [];
90 90
 
91 91
         foreach ($events as $event) {
92
-            $key = $event->type . ':' . $event->identifier; // Chiave univoca per type + identifier
92
+            $key = $event->type.':'.$event->identifier; // Chiave univoca per type + identifier
93 93
             $event->event_time = \Illuminate\Support\Carbon::parse($event->event_time);
94 94
             // 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
95 95
             if (!isset($unique_events[$key]) || $event->event_time <= $unique_events[$key]->event_time) {
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
 
100 100
         $unique_events = array_values($unique_events);
101 101
 
102
-        $this->logIf('Eventi unici ' . count($unique_events));
102
+        $this->logIf('Eventi unici '.count($unique_events));
103 103
         // Quando il numero di eventi unici è inferiore al batchSize e quello più vecchio aspetta da almeno due minuti, mando l'invalidazione.
104 104
         // Questo serve per i siti piccoli che hanno pochi eventi, altrimenti si rischia di attendere troppo per invalidare i tags
105 105
         // In questo caso invalido i tag/key "unici" e setto a processed = 1 tutti quelli recuperati
106 106
         if (count($unique_events) < $this->tagBatchSize && $processingStartTime->diffInSeconds($unique_events[0]->event_time) >= 120) {
107
-            $this->logIf('Il numero di eventi unici è inferiore al batchSize ( ' . $this->tagBatchSize . ' ) e sono passati più di due minuti, procedo');
107
+            $this->logIf('Il numero di eventi unici è inferiore al batchSize ( '.$this->tagBatchSize.' ) e sono passati più di due minuti, procedo');
108 108
             $this->processBatch($events, $unique_events);
109 109
 
110 110
             return;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             // altrimenti aggiungo l'evento a quelli da processare
125 125
             $eventsToUpdate[] = $event;
126 126
             // e recupero tutti gli ID che hanno quel tag/key
127
-            $eventsAll[] = array_filter($events, function ($event) use ($typeFilter, $identifierFilter) {
127
+            $eventsAll[] = array_filter($events, function($event) use ($typeFilter, $identifierFilter) {
128 128
                 return $event->type === $typeFilter && $event->identifier === $identifierFilter;
129 129
             });
130 130
         }
@@ -143,15 +143,15 @@  discard block
 block discarded – undo
143 143
         foreach ($eventsToInvalidate as $item) {
144 144
             switch ($item->type) {
145 145
                 case 'key':
146
-                    $keys[] = $item->identifier . '§' . $item->connection_name;
146
+                    $keys[] = $item->identifier.'§'.$item->connection_name;
147 147
                     break;
148 148
                 case 'tag':
149
-                    $tags[] = $item->identifier . '§' . $item->connection_name;
149
+                    $tags[] = $item->identifier.'§'.$item->connection_name;
150 150
                     break;
151 151
             }
152 152
         }
153 153
 
154
-        $this->logIf('Invalido ' . count($keys) . ' chiavi e ' . count($tags) . ' tags' . ' per un totale di ' . count($allEvents) . ' events_ID');
154
+        $this->logIf('Invalido '.count($keys).' chiavi e '.count($tags).' tags'.' per un totale di '.count($allEvents).' events_ID');
155 155
 
156 156
         if (!empty($keys)) {
157 157
             $this->invalidateKeys($keys);
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
                 continue;
197 197
             }
198 198
             // oppure di default uso Laravel
199
-            $storeName =  $this->getStoreFromConnectionName($connection_name);
199
+            $storeName = $this->getStoreFromConnectionName($connection_name);
200 200
 
201 201
             if ($storeName === null) {
202 202
                 continue;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
             return;
234 234
         }
235 235
         foreach ($groupByConnection as $connection_name => $arrTags) {
236
-            $storeName =  $this->getStoreFromConnectionName($connection_name);
236
+            $storeName = $this->getStoreFromConnectionName($connection_name);
237 237
             if ($storeName === null) {
238 238
                 continue;
239 239
             }
@@ -254,13 +254,13 @@  discard block
 block discarded – undo
254 254
         $tagBatchSize = $this->option('tag-batch-size') ?? config('super_cache_invalidate.tag_batch_size');
255 255
         $this->tagBatchSize = (int) $tagBatchSize;
256 256
         $this->connection_name = $this->option('connection_name') ?? config('super_cache_invalidate.default_connection_name');
257
-        $this->log_attivo = $this->option('log_attivo') && (int)$this->option('log_attivo') === 1;
257
+        $this->log_attivo = $this->option('log_attivo') && (int) $this->option('log_attivo') === 1;
258 258
         $this->invalidation_window = (int) config('super_cache_invalidate.invalidation_window');
259 259
         $lockTimeout = (int) config('super_cache_invalidate.lock_timeout');
260 260
 
261 261
         // Acquisisco il lock in modo da essere sicura che le esecuzioni non si accavallino
262 262
         // $lockValue = $this->helper->acquireShardLock($this->shardId, $this->priority, $lockTimeout, $this->connection_name);
263
-        $this->logIf('Starting Elaborazione ...' . $this->invalidation_window);
263
+        $this->logIf('Starting Elaborazione ...'.$this->invalidation_window);
264 264
         // if (!$lockValue) {
265 265
         //    return;
266 266
         //}
@@ -279,6 +279,6 @@  discard block
 block discarded – undo
279 279
             // $this->helper->releaseShardLock($this->shardId, $this->priority, $lockValue, $this->connection_name);
280 280
         }
281 281
         $executionTime = (microtime(true) - $startTime) * 1000;
282
-        $this->logIf('Fine Elaborazione - Tempo di esecuzione: ' . $executionTime . ' millisec.');
282
+        $this->logIf('Fine Elaborazione - Tempo di esecuzione: '.$executionTime.' millisec.');
283 283
     }
284 284
 }
Please login to merge, or discard this patch.