@@ -59,14 +59,28 @@ private function getStoreFromConnectionName(string $connection_name): ?string
59
59
return null ;
60
60
}
61
61
62
- protected function getCache_invalidation_eventsPartitionName (int $ shardId , int $ priority , int $ processed , Carbon $ processingStartTime ): string
62
+ protected function getCache_invalidation_eventsPartitionName (int $ shardId , int $ priorityId ): string
63
63
{
64
- if ($ processed === 0 ) {
65
- return "p_unprocessed_s {$ shardId }_p {$ priority }" ;
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
+ }
66
81
}
67
- $ year = $ processingStartTime ->year ;
68
- $ week = $ processingStartTime ->weekOfYear ;
69
- return "p_s {$ shardId }_p {$ priority }_ {$ year }w {$ week }" ;
82
+
83
+ return '' ;
70
84
}
71
85
72
86
/**
@@ -86,19 +100,21 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
86
100
87
101
// Fetch a batch of unprocessed events
88
102
$ partitionCache_invalidation_events = $ this ->getCache_invalidation_eventsPartitionName ($ shardId , $ priority , 0 , $ processingStartTime );
103
+
89
104
$ events = DB ::table (DB ::raw ("`cache_invalidation_events` PARTITION ( {$ partitionCache_invalidation_events }) " ))
90
105
//->from(DB::raw("`{$this->from}` PARTITION ({$partitionsString})"))
91
- ->where ('processed ' , '= ' , 0 )
92
- ->where ('shard ' , '= ' , $ shardId )
93
- ->where ('priority ' , '= ' , $ priority )
94
- ->where ('event_time ' , '< ' , $ processingStartTime )
106
+ ->where ('processed ' , '= ' , 0 )
107
+ ->where ('shard ' , '= ' , $ shardId )
108
+ ->where ('priority ' , '= ' , $ priority )
109
+ ->where ('event_time ' , '< ' , $ processingStartTime )
95
110
// Cerco tutte le chiavi/tag da invalidare per questo database redis
96
- ->where ('connection_name ' , '= ' , $ connection_name )
97
- ->orderBy ('event_time ' )
98
- ->limit ($ limit )
99
- ->get ()
111
+ ->where ('connection_name ' , '= ' , $ connection_name )
112
+ ->orderBy ('event_time ' )
113
+ ->limit ($ limit )
114
+ ->get ()
100
115
;
101
116
117
+ //ds($partitionCache_invalidation_events . ' -> Shard (' . $shardId . ') Priority (' . $priority . ') Record = ' . $events->count());
102
118
if ($ events ->isEmpty ()) {
103
119
// No more events to process
104
120
return ;
@@ -118,11 +134,10 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
118
134
119
135
//retrive associated identifiers related to fetched event id
120
136
// Per le chiavi/tag associati non filtro per connection_name, potrebbero esserci associazioni anche in altri database
121
- $ partitionCache_invalidation_event_associations = "p_ {$ processingStartTime ->year }w {$ processingStartTime ->weekOfYear }" ;
122
- $ associations = DB ::table (DB ::raw ("`cache_invalidation_event_associations` PARTITION ( {$ partitionCache_invalidation_event_associations }) " ))
123
- ->whereIn ('event_id ' , $ eventIds )
124
- ->get ()
125
- ->groupBy ('event_id ' )
137
+ $ associations = DB ::table ('cache_invalidation_event_associations ' )
138
+ ->whereIn ('event_id ' , $ eventIds )
139
+ ->get ()
140
+ ->groupBy ('event_id ' )
126
141
;
127
142
128
143
// Prepare list of all identifiers to fetch last invalidation times
@@ -306,10 +321,10 @@ protected function updateLastInvalidationTimes(array $identifiers): void
306
321
foreach ($ identifiers as $ key ) {
307
322
[$ type , $ identifier ] = explode (': ' , $ key , 2 );
308
323
DB ::table ('cache_invalidation_timestamps ' )
309
- ->updateOrInsert (
310
- ['identifier_type ' => $ type , 'identifier ' => $ identifier ],
311
- ['last_invalidated ' => $ now ]
312
- )
324
+ ->updateOrInsert (
325
+ ['identifier_type ' => $ type , 'identifier ' => $ identifier ],
326
+ ['last_invalidated ' => $ now ]
327
+ )
313
328
;
314
329
}
315
330
}
@@ -376,8 +391,8 @@ protected function processBatch(array $batchIdentifiers, array $eventsToUpdate):
376
391
377
392
// Mark events as processed
378
393
DB ::table ('cache_invalidation_events ' )
379
- ->whereIn ('id ' , $ eventsToUpdate )
380
- ->update (['processed ' => 1 ])
394
+ ->whereIn ('id ' , $ eventsToUpdate )
395
+ ->update (['processed ' => 1 ])
381
396
;
382
397
383
398
// Commit transaction
0 commit comments