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 Feb 13, 2025
1 parent e45231b commit ec21147
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 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]);

Check warning on line 52 in app/Console/Commands/AutoUpdateUserLastActions.php

View workflow job for this annotation

GitHub Actions / ubuntu-22.04

Unknown word (LRANGE)

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]);

Check warning on line 76 in app/Console/Commands/AutoUpsertHistories.php

View workflow job for this annotation

GitHub Actions / ubuntu-22.04

Unknown word (LRANGE)

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]);

Check warning on line 60 in app/Console/Commands/AutoUpsertPeers.php

View workflow job for this annotation

GitHub Actions / ubuntu-22.04

Unknown word (LRANGE)

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
6 changes: 3 additions & 3 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
if (! config('announce.external_tracker.is_enabled')) {
$schedule->command('auto:upsert_peers')->everyFiveSeconds();
$schedule->command('auto:upsert_histories')->everyFiveSeconds();
$schedule->command('auto:upsert_announces')->everyFiveSeconds();
$schedule->command('auto:upsert_peers')->everyFiveSeconds()->withoutOverlapping(2);
$schedule->command('auto:upsert_histories')->everyFiveSeconds()->withoutOverlapping(2);
$schedule->command('auto:upsert_announces')->everyFiveSeconds()->withoutOverlapping(2);
$schedule->command('auto:cache_user_leech_counts')->everyThirtyMinutes();
$schedule->command('auto:sync_peers')->everyFiveMinutes();
$schedule->command('auto:torrent_balance')->hourly();
Expand Down

0 comments on commit ec21147

Please sign in to comment.