| @@ -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); | 
| @@ -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 | } | 
| @@ -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); | 
| @@ -165,7 +165,7 @@ discard block | ||
| 165 | 165 | |
| 166 | 166 |          if (!empty($tags)) { | 
| 167 | 167 | // Escludo i tag fullpage | 
| 168 | -            $tags = array_filter($tags, function ($item) { | |
| 168 | +            $tags = array_filter($tags, function($item) { | |
| 169 | 169 | return !str_contains($item, 'fullpage'); | 
| 170 | 170 | }); | 
| 171 | 171 | $this->invalidateTags($tags); | 
| @@ -209,7 +209,7 @@ discard block | ||
| 209 | 209 | continue; | 
| 210 | 210 | } | 
| 211 | 211 | // oppure di default uso Laravel | 
| 212 | - $storeName = $this->getStoreFromConnectionName($connection_name); | |
| 212 | + $storeName = $this->getStoreFromConnectionName($connection_name); | |
| 213 | 213 | |
| 214 | 214 |              if ($storeName === null) { | 
| 215 | 215 | continue; | 
| @@ -246,7 +246,7 @@ discard block | ||
| 246 | 246 | return; | 
| 247 | 247 | } | 
| 248 | 248 |          foreach ($groupByConnection as $connection_name => $arrTags) { | 
| 249 | - $storeName = $this->getStoreFromConnectionName($connection_name); | |
| 249 | + $storeName = $this->getStoreFromConnectionName($connection_name); | |
| 250 | 250 |              if ($storeName === null) { | 
| 251 | 251 | continue; | 
| 252 | 252 | } | 
| @@ -267,13 +267,13 @@ discard block | ||
| 267 | 267 |          $tagBatchSize = $this->option('tag-batch-size') ?? config('super_cache_invalidate.tag_batch_size'); | 
| 268 | 268 | $this->tagBatchSize = (int) $tagBatchSize; | 
| 269 | 269 |          $this->connection_name = $this->option('connection_name') ?? config('super_cache_invalidate.default_connection_name'); | 
| 270 | -        $this->log_attivo = $this->option('log_attivo') && (int)$this->option('log_attivo') === 1; | |
| 270 | +        $this->log_attivo = $this->option('log_attivo') && (int) $this->option('log_attivo') === 1; | |
| 271 | 271 |          $this->invalidation_window = (int) config('super_cache_invalidate.invalidation_window'); | 
| 272 | 272 |          $lockTimeout = (int) config('super_cache_invalidate.lock_timeout'); | 
| 273 | 273 | |
| 274 | 274 | // Acquisisco il lock in modo da essere sicura che le esecuzioni non si accavallino | 
| 275 | 275 | // $lockValue = $this->helper->acquireShardLock($this->shardId, $this->priority, $lockTimeout, $this->connection_name); | 
| 276 | -        $this->logIf('Starting Elaborazione ...' . $this->invalidation_window); | |
| 276 | +        $this->logIf('Starting Elaborazione ...'.$this->invalidation_window); | |
| 277 | 277 |          // if (!$lockValue) { | 
| 278 | 278 | // return; | 
| 279 | 279 | // } | 
| @@ -290,6 +290,6 @@ discard block | ||
| 290 | 290 | ), 'error'); | 
| 291 | 291 | } | 
| 292 | 292 | $executionTime = (microtime(true) - $startTime) * 1000; | 
| 293 | -        $this->logIf('Fine Elaborazione - Tempo di esecuzione: ' . $executionTime . ' millisec.'); | |
| 293 | +        $this->logIf('Fine Elaborazione - Tempo di esecuzione: '.$executionTime.' millisec.'); | |
| 294 | 294 | } | 
| 295 | 295 | } |