Skip to content

Commit c5069f0

Browse files
Merge pull request #3 from padosoft/m-jb-test-super-cache-invalidate
use partition
2 parents e10b1fb + aa8835d commit c5069f0

File tree

6 files changed

+441
-144
lines changed

6 files changed

+441
-144
lines changed

database/migrations/2024_11_20_200800_create_cache_invalidation_events_table.php renamed to database/migrations/2025_01_08_400999_create_cache_invalidation_events_table.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
protected function generatePartitionSQL(): string
1313
{
14-
$startYear = 2024;
14+
$startYear = 2025;
1515
$endYear = 2030;
1616
$shards = config('super_cache_invalidate.total_shards', 10);
1717
$priorities = [0, 1]; // Adjust as needed
@@ -21,9 +21,11 @@ protected function generatePartitionSQL(): string
2121
// Partitions for unprocessed events
2222
foreach ($priorities as $priority) {
2323
for ($shard = 0; $shard < $shards; $shard++) {
24-
$partitionName = "p_unprocessed_s{$shard}_p{$priority}";
25-
$partitionValue = ($priority * $shards) + $shard + 1;
26-
$partitionStatements[] = "PARTITION {$partitionName} VALUES LESS THAN ({$partitionValue})";
24+
$partitionValue = ($priority * 10) + $shard;
25+
//$partitionName = "p_unprocessed_s{$shard}_p{$priority}";
26+
$partitionName = "p_unprocessed_{$partitionValue}";
27+
$nextPartitionKey = $partitionValue + 1;
28+
$partitionStatements[] = "PARTITION {$partitionName} VALUES LESS THAN ({$nextPartitionKey})";
2729
}
2830
}
2931

@@ -32,9 +34,11 @@ protected function generatePartitionSQL(): string
3234
for ($week = 1; $week <= 53; $week++) {
3335
foreach ($priorities as $priority) {
3436
for ($shard = 0; $shard < $shards; $shard++) {
35-
$partitionKey = ($year * 10000) + ($week * 100) + ($priority * $shards) + $shard;
36-
$nextPartitionKey = $partitionKey + 1;
37-
$partitionName = "p_s{$shard}_p{$priority}_{$year}w{$week}";
37+
$partitionValue = ($year * 10000) + ($week * 100) + ($priority * 10) + $shard;
38+
//$nextPartitionKey = $partitionKey + 1;
39+
//$partitionName = "p_s{$shard}_p{$priority}_{$year}w{$week}";
40+
$partitionName = "p_processed_{$partitionValue}";
41+
$nextPartitionKey = $partitionValue + 1;
3842
$partitionStatements[] = "PARTITION {$partitionName} VALUES LESS THAN ({$nextPartitionKey})";
3943
}
4044
}
@@ -53,9 +57,9 @@ protected function generatePartitionSQL(): string
5357
*/
5458
public function up(): void
5559
{
56-
if (Schema::hasTable('cache_invalidation_events')) {
57-
return;
58-
}
60+
61+
// Per i siti in cui l'ho già creata (lvr, Santha, Pissei) la ricreo con le partizioni giuste
62+
Schema::dropIfExists('cache_invalidation_events');
5963

6064
Schema::create('cache_invalidation_events', function (Blueprint $table) {
6165
//$table->bigIncrements('id');
@@ -66,16 +70,18 @@ public function up(): void
6670
$table->string('reason')->nullable()->comment('Reason for the invalidation (for logging purposes)');
6771
$table->tinyInteger('priority')->default(0)->comment('Priority of the event');
6872
$table->dateTime('event_time')->default(DB::raw('CURRENT_TIMESTAMP'))->comment('Timestamp when the event was created');
73+
$table->dateTime('created_at')->default(DB::raw('CURRENT_TIMESTAMP'))->comment('Timestamp when the record was created');
74+
$table->dateTime('updated_at')->default(DB::raw('CURRENT_TIMESTAMP'))->comment('Timestamp when the record was updated');
6975
$table->boolean('processed')->default(0)->comment('Flag indicating whether the event has been processed');
7076
$table->integer('shard')->comment('Shard number for parallel processing');
7177

7278
// Partition key as a generated stored column
7379
$table->integer('partition_key')->storedAs('
7480
CASE
7581
WHEN `processed` = 0 THEN
76-
(`priority` * `shard`) + `shard` + 1
82+
(`priority` * 10) + `shard`
7783
ELSE
78-
(YEAR(`event_time`) * 10000) + (WEEK(`event_time`, 3) * 100) + (`priority` * `shard`) + `shard`
84+
(YEAR(`event_time`) * 10000) + (WEEK(`event_time`, 3) * 100) + (`priority` * 10) + `shard`
7985
END
8086
')->comment('Partition key for efficient querying and partitioning');
8187

0 commit comments

Comments
 (0)