Skip to content

Commit

Permalink
update: only delete upsert data after successful upsertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Roardom committed Jun 23, 2024
1 parent efd76c3 commit 7fd03c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/Console/Commands/AutoUpdateUserLastActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final public function handle(): void

$userIdCount = Redis::command('LLEN', [$key]);

$userIds = Redis::command('LPOP', [$key, $userIdCount]);
$userIds = Redis::command('LRANGE', [$key, 0, $userIdCount - 1]);

if ($userIds !== false) {
DB::transaction(static function () use ($userIds): void {
Expand All @@ -61,6 +61,8 @@ final public function handle(): void
}, 5);
}

Redis::command('LTRIM', [$key, $userIdCount, -1])

$this->comment('Automated upsert histories command complete');
}
}
4 changes: 3 additions & 1 deletion app/Console/Commands/AutoUpsertHistories.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final public function handle(): void
$historyCount = Redis::connection('announce')->command('LLEN', [$key]);

for ($historiesLeft = $historyCount; $historiesLeft > 0; $historiesLeft -= $historiesPerCycle) {
$histories = Redis::connection('announce')->command('LPOP', [$key, $historiesPerCycle]);
$histories = Redis::connection('announce')->command('LRANGE', [$key, 0, $historiesPerCycle - 1]);

if ($histories === false) {
break;
Expand Down Expand Up @@ -103,6 +103,8 @@ final public function handle(): void
],
);
}, 5);

Redis::connection('announce')->command('LTRIM', [$key, $historiesPerCycle, -1]);
}

$this->comment('Automated upsert histories command complete');
Expand Down
4 changes: 3 additions & 1 deletion app/Console/Commands/AutoUpsertPeers.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final public function handle(): void
$peerCount = Redis::connection('announce')->command('LLEN', [$key]);

for ($peersLeft = $peerCount; $peersLeft > 0; $peersLeft -= $peerPerCycle) {
$peers = Redis::connection('announce')->command('LPOP', [$key, $peerPerCycle]);
$peers = Redis::connection('announce')->command('LRANGE', [$key, 0, $peerPerCycle - 1]);

if ($peers === false) {
break;
Expand Down Expand Up @@ -86,6 +86,8 @@ final public function handle(): void
],
);
}, 5);

Redis::connection('announce')->command('LTRIM', [$key, $peerPerCycle, -1]);
}

$this->comment('Automated insert peers command complete');
Expand Down

0 comments on commit 7fd03c0

Please sign in to comment.