@@ -59,29 +59,7 @@ private function getStoreFromConnectionName(string $connection_name): ?string
5959 return null ;
6060 }
6161
62- protected function getCache_invalidation_eventsPartitionName (int $ shardId , int $ priorityId ): string
63- {
64- // Calcola il valore della partizione
65- $ shards = config ('super_cache_invalidate.total_shards ' , 10 );
66- $ priorities = [0 , 1 ];
67-
68- $ partitionStatements = [];
69-
70- $ partitionValueId = ($ priorityId * $ shards ) + $ shardId + 1 ;
71-
72- // Partitions for unprocessed events
73- foreach ($ priorities as $ priority ) {
74- for ($ shard = 0 ; $ shard < $ shards ; $ shard ++) {
75- $ partitionName = "p_unprocessed_s {$ shard }_p {$ priority }" ;
76- $ partitionValue = ($ priority * $ shards ) + $ shard + 1 ;
77- if ($ partitionValueId < $ partitionValue ) {
78- return $ partitionName ;
79- }
80- }
81- }
8262
83- return '' ;
84- }
8563
8664 /**
8765 * Process cache invalidation events.
@@ -100,7 +78,7 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
10078 $ invalidationWindow = config ('super_cache_invalidate.invalidation_window ' );
10179
10280 // Fetch a batch of unprocessed events
103- $ partitionCache_invalidation_events = $ this ->getCache_invalidation_eventsPartitionName ($ shardId , $ priority, 0 , $ processingStartTime );
81+ $ partitionCache_invalidation_events = $ this ->helper -> getCacheInvalidationEventsPartitionName ($ shardId , $ priority );
10482
10583 $ events = DB ::table (DB ::raw ("`cache_invalidation_events` PARTITION ( {$ partitionCache_invalidation_events }) " ))
10684 //->from(DB::raw("`{$this->from}` PARTITION ({$partitionsString})"))
@@ -131,6 +109,9 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
131109 $ counter = 0 ;
132110
133111 // Fetch associated identifiers for the events
112+ // TODO JB 31/12/2024: per adesso commentato, da riattivare quando tutto funziona alla perfezione usando la partizione
113+ $ associations = collect ();
114+ /*
134115 $eventIds = $events->pluck('id')->all();
135116
136117 //retrive associated identifiers related to fetched event id
@@ -140,6 +121,7 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
140121 ->get()
141122 ->groupBy('event_id')
142123 ;
124+ */
143125
144126 // Prepare list of all identifiers to fetch last invalidation times
145127 $ allIdentifiers = [];
@@ -215,7 +197,7 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
215197
216198 // When we reach the batch size, process the accumulated identifiers
217199 if ($ counter % $ tagBatchSize === 0 ) {
218- $ this ->processBatch ($ batchIdentifiers , $ eventsToUpdate );
200+ $ this ->processBatch ($ batchIdentifiers , $ eventsToUpdate, $ shardId , $ priority );
219201
220202 // Reset the accumulators
221203 $ batchIdentifiers = [];
@@ -228,7 +210,7 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
228210 }
229211
230212 // Process any remaining identifiers in the batch
231- $ this ->processBatch ($ batchIdentifiers , $ eventsToUpdate );
213+ $ this ->processBatch ($ batchIdentifiers , $ eventsToUpdate, $ shardId , $ priority );
232214 }
233215
234216 /**
@@ -338,7 +320,7 @@ protected function updateLastInvalidationTimes(array $identifiers): void
338320 *
339321 * @throws \Throwable
340322 */
341- protected function processBatch (array $ batchIdentifiers , array $ eventsToUpdate ): void
323+ protected function processBatch (array $ batchIdentifiers , array $ eventsToUpdate, int $ shard , int $ priority ): void
342324 {
343325 $ maxAttempts = 5 ;
344326 $ attempts = 0 ;
@@ -395,7 +377,8 @@ protected function processBatch(array $batchIdentifiers, array $eventsToUpdate):
395377
396378 try {
397379 // Mark events as processed
398- DB ::table ('cache_invalidation_events ' )
380+ $ partitionCache_invalidation_events = $ this ->helper ->getCacheInvalidationEventsPartitionName ($ shard , $ priority );
381+ DB ::table (DB ::raw ("`cache_invalidation_events` PARTITION ( {$ partitionCache_invalidation_events }) " ))
399382 ->whereIn ('id ' , $ eventsToUpdate )
400383 ->update (['processed ' => 1 ])
401384 ;
@@ -512,7 +495,7 @@ public function handle(): void
512495 try {
513496 $ this ->processEvents ($ shardId , $ priority , $ limit , $ tagBatchSize , $ connection_name );
514497 } catch (\Throwable $ e ) {
515- $ this ->error (' Si è verificato un errore in ' . __METHOD__ . ': ' . $ e ->getMessage ());
498+ $ this ->error (now () . ' Si è verificato un errore in ' . __METHOD__ . ': ' . $ e ->getMessage ());
516499 } finally {
517500 $ this ->helper ->releaseShardLock ($ shardId , $ priority , $ lockValue , $ connection_name );
518501 }
0 commit comments