Skip to content

Commit fefcdd0

Browse files
committed
use partition
1 parent 0786af8 commit fefcdd0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Console/ProcessCacheInvalidationEventsCommand.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ private function getStoreFromConnectionName(string $connection_name): ?string
5959
return null;
6060
}
6161

62+
protected function getCache_invalidation_eventsPartitionName(int $shardId, int $priority, int $processed, Carbon $processingStartTime): string
63+
{
64+
if ($processed === 0) {
65+
return "p_unprocessed_s{$shardId}_p{$priority}";
66+
}
67+
$year = $processingStartTime->year;
68+
$week = $processingStartTime->weekOfYear;
69+
return "p_s{$shardId}_p{$priority}_{$year}w{$week}";
70+
}
71+
6272
/**
6373
* Process cache invalidation events.
6474
*
@@ -75,7 +85,9 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
7585
$invalidationWindow = config('super_cache_invalidate.invalidation_window');
7686

7787
// Fetch a batch of unprocessed events
78-
$events = DB::table('cache_invalidation_events')
88+
$partitionCache_invalidation_events = $this->getCache_invalidation_eventsPartitionName($shardId, $priority, 0, $processingStartTime);
89+
$events = DB::table(DB::raw("`cache_invalidation_events` PARTITION ({$partitionCache_invalidation_events})"))
90+
//->from(DB::raw("`{$this->from}` PARTITION ({$partitionsString})"))
7991
->where('processed', '=', 0)
8092
->where('shard', '=', $shardId)
8193
->where('priority', '=', $priority)
@@ -106,7 +118,8 @@ protected function processEvents(int $shardId, int $priority, int $limit, int $t
106118

107119
//retrive associated identifiers related to fetched event id
108120
// Per le chiavi/tag associati non filtro per connection_name, potrebbero esserci associazioni anche in altri database
109-
$associations = DB::table('cache_invalidation_event_associations')
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})"))
110123
->whereIn('event_id', $eventIds)
111124
->get()
112125
->groupBy('event_id')
@@ -313,7 +326,7 @@ protected function processBatch(array $batchIdentifiers, array $eventsToUpdate):
313326
{
314327

315328
// Begin transaction for the batch
316-
DB::beginTransaction();
329+
// DB::beginTransaction();
317330

318331
try {
319332
// Separate keys and tags
@@ -368,10 +381,10 @@ protected function processBatch(array $batchIdentifiers, array $eventsToUpdate):
368381
;
369382

370383
// Commit transaction
371-
DB::commit();
384+
//DB::commit();
372385
} catch (\Exception $e) {
373386
// Rollback transaction on error
374-
DB::rollBack();
387+
// DB::rollBack();
375388
throw $e;
376389
}
377390
}

0 commit comments

Comments
 (0)