@@ -181,14 +181,14 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
181181
182182 // Mark all events in the group as processed
183183 foreach ($ eventsGroup as $ event ) {
184- $ eventsToUpdate [] = $ event ->id ;
184+ $ eventsToUpdate [] = [ ' id ' => $ event ->id , ' event_time ' => $ event -> event_time , ' partition_key ' => $ event -> partition_key ] ;
185185 }
186186 } else {
187187 // Within the invalidation window, skip invalidation
188188 // Mark all events except the last one as processed
189189 $ eventsToProcess = $ eventsGroup ->slice (0 , -1 );
190190 foreach ($ eventsToProcess as $ event ) {
191- $ eventsToUpdate [] = $ event ->id ;
191+ $ eventsToUpdate [] = [ ' id ' => $ event ->id , ' event_time ' => $ event -> event_time , ' partition_key ' => $ event -> partition_key ] ;
192192 }
193193 // The last event remains unprocessed
194194 }
@@ -304,12 +304,12 @@ protected function updateLastInvalidationTimes(array $identifiers): void
304304
305305 foreach ($ identifiers as $ key ) {
306306 [$ type , $ identifier ] = explode (': ' , $ key , 2 );
307- // Qui si può usare la partizione
308- $ partitionCache_invalidation_timestamps = $ this ->helper ->getCacheInvalidationTimestampsPartitionName ();
307+ // Anche qui non si può usare la partizione perchè nel caso dell'update potrebbe non essere la partizione giusta temporalmente
308+ // $partitionCache_invalidation_timestamps = $this->helper->getCacheInvalidationTimestampsPartitionName();
309309
310- // DB::table('cache_invalidation_timestamps')
311- DB ::table (DB ::raw ("`cache_invalidation_timestamps` PARTITION ( {$ partitionCache_invalidation_timestamps }) " ))
312- ->updateOrInsert (
310+ DB ::table ('cache_invalidation_timestamps ' )
311+ // DB::table(DB::raw("`cache_invalidation_timestamps` PARTITION ({$partitionCache_invalidation_timestamps})"))
312+ ->updateOrInsert (
313313 ['identifier_type ' => $ type , 'identifier ' => $ identifier ],
314314 ['last_invalidated ' => $ now ]
315315 )
@@ -377,38 +377,40 @@ protected function processBatch(array $batchIdentifiers, array $eventsToUpdate,
377377 }
378378
379379 $ shards = config ('super_cache_invalidate.total_shards ' , 10 );
380- $ partitionCache_invalidation_events = $ this ->helper ->getCacheInvalidationEventsPartitionName ($ shard , $ priority );
381- $ partitionKey = ($ priority * $ shards ) + $ shard + 1 ;
382- foreach ($ eventsToUpdate as $ eventToUpdateId ) {
383- while ($ attempts < $ maxAttempts && !$ updatedOk ) {
384- // Begin transaction for the batch
385- DB ::beginTransaction ();
386- try {
387- // Disabilita i controlli delle chiavi esterne e dei vincoli univoci
388- DB ::statement ('SET FOREIGN_KEY_CHECKS=0; ' );
389- DB ::statement ('SET UNIQUE_CHECKS=0; ' );
390- // Mark event as processed
391- DB ::table (DB ::raw ("`cache_invalidation_events` PARTITION ( {$ partitionCache_invalidation_events }) " ))
392- ->where ('id ' , $ eventToUpdateId )
393- ->where ('partition_key ' , $ partitionKey )
394- ->update (['processed ' => 1 ])
395- ;
396- // Riattiva i controlli
397- DB ::statement ('SET UNIQUE_CHECKS=1; ' );
398- DB ::statement ('SET FOREIGN_KEY_CHECKS=1; ' );
399- // Commit transaction
400- DB ::commit ();
401- $ updatedOk = true ;
402- } catch (\Throwable $ e ) {
403- // Rollback transaction on error
404- DB ::rollBack ();
405- $ attempts ++;
406- $ this ->warn (now ()->toDateTimeString () . ": Tentativo $ attempts di $ maxAttempts: " . $ e ->getMessage ());
407- // Logica per gestire i tentativi falliti
408- if ($ attempts >= $ maxAttempts ) {
409- // Salta il record dopo il numero massimo di tentativi
410- throw $ e ;
411- }
380+ //$partitionCache_invalidation_events = $this->helper->getCacheInvalidationEventsPartitionName($shard, $priority);
381+
382+ while ($ attempts < $ maxAttempts && !$ updatedOk ) {
383+ //$partitionCache_invalidation_events_processed = $this->helper->getCacheInvalidationEventsProcessedPartitionName($shard, $priority, $eventToUpdate['event_time']);
384+
385+ // Begin transaction for the batch
386+ //DB::beginTransaction();
387+ try {
388+ // Disabilita i controlli delle chiavi esterne e dei vincoli univoci
389+ DB ::statement ('SET FOREIGN_KEY_CHECKS=0; ' );
390+ DB ::statement ('SET UNIQUE_CHECKS=0; ' );
391+
392+ // Mark event as processed
393+ //DB::table(DB::raw("`cache_invalidation_events` PARTITION ({$partitionCache_invalidation_events}, {$partitionCache_invalidation_events_processed})"))
394+ DB ::table ("cache_invalidation_events " )
395+ ->whereIn ('id ' , array_column ($ eventsToUpdate , 'id ' ))
396+ ->whereIn ('partition_key ' , array_column ($ eventsToUpdate , 'partition_key ' ))
397+ ->update (['processed ' => 1 ])
398+ ;
399+ // Riattiva i controlli
400+ DB ::statement ('SET UNIQUE_CHECKS=1; ' );
401+ DB ::statement ('SET FOREIGN_KEY_CHECKS=1; ' );
402+ // Commit transaction
403+ //DB::commit();
404+ $ updatedOk = true ;
405+ } catch (\Throwable $ e ) {
406+ // Rollback transaction on error
407+ //DB::rollBack();
408+ $ attempts ++;
409+ $ this ->warn (now ()->toDateTimeString () . ": Tentativo $ attempts di $ maxAttempts: " . $ e ->getMessage ());
410+ // Logica per gestire i tentativi falliti
411+ if ($ attempts >= $ maxAttempts ) {
412+ // Salta il record dopo il numero massimo di tentativi
413+ throw $ e ;
412414 }
413415 }
414416 }
0 commit comments