From 68b391785b8f1a5a93b345121df939bab3668f66 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Tue, 25 Jul 2023 00:57:03 +0800 Subject: [PATCH] set cleanup batch ttl --- app/Jobs/UpdateTorrentSeedersEtc.php | 3 +++ app/Jobs/UpdateUserSeedingLeechingTime.php | 3 +++ app/Repositories/CleanupRepository.php | 10 ++++++++-- include/constants.php | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Jobs/UpdateTorrentSeedersEtc.php b/app/Jobs/UpdateTorrentSeedersEtc.php index 1be5f0e1..de1b63cf 100644 --- a/app/Jobs/UpdateTorrentSeedersEtc.php +++ b/app/Jobs/UpdateTorrentSeedersEtc.php @@ -64,6 +64,9 @@ class UpdateTorrentSeedersEtc implements ShouldQueue $torrentIdArr = explode(",", $this->idStr); foreach ($torrentIdArr as $torrentId) { + if ($torrentId <= 0) { + continue; + } $peerResult = NexusDB::table('peers') ->where('torrent', $torrentId) ->selectRaw("count(*) as count, seeder") diff --git a/app/Jobs/UpdateUserSeedingLeechingTime.php b/app/Jobs/UpdateUserSeedingLeechingTime.php index 6b540037..9cde9c19 100644 --- a/app/Jobs/UpdateUserSeedingLeechingTime.php +++ b/app/Jobs/UpdateUserSeedingLeechingTime.php @@ -65,6 +65,9 @@ class UpdateUserSeedingLeechingTime implements ShouldQueue $count = 0; $uidArr = explode(",", $this->idStr); foreach ($uidArr as $uid) { + if ($uid <= 0) { + continue; + } $sumInfo = NexusDB::table('snatched') ->selectRaw('sum(seedtime) as seedtime_sum, sum(leechtime) as leechtime_sum') ->where('userid', $uid) diff --git a/app/Repositories/CleanupRepository.php b/app/Repositories/CleanupRepository.php index 30d011db..8a3c3406 100644 --- a/app/Repositories/CleanupRepository.php +++ b/app/Repositories/CleanupRepository.php @@ -12,6 +12,8 @@ class CleanupRepository extends BaseRepository const USER_SEEDING_LEECHING_TIME_BATCH_KEY = "batch_key:user_seeding_leeching_time"; const TORRENT_SEEDERS_ETC_BATCH_KEY = "batch_key:torrent_seeders_etc"; + const KEY_LIFETIME = 3600*3; + private static array $batchKeyActionsMap = [ self::USER_SEED_BONUS_BATCH_KEY => [ 'action' => 'seed_bonus', @@ -79,7 +81,11 @@ class CleanupRepository extends BaseRepository return; } //update the batch key - $redis->set($batchKey, $batchKey . ":" . self::getHashKeySuffix()); + $newBatch = $batchKey . ":" . self::getHashKeySuffix(); + $redis->set($batchKey, $newBatch, ['ex' => self::KEY_LIFETIME]); + $redis->hSetNx($newBatch, -1, 1); + $redis->expire($newBatch, self::KEY_LIFETIME); + $count = 0; $it = NULL; @@ -95,7 +101,7 @@ class CleanupRepository extends BaseRepository $batchKeyInfo['action'], 0, 0, $idStr, $requestId, $delay ); $output = executeCommand($command, 'string', true); - do_log(sprintf('command: %s, output: %s', $command, $output)); + do_log(sprintf('output: %s', $output)); $count += count($arr_keys); $page++; } diff --git a/include/constants.php b/include/constants.php index 1991000f..f42afe8e 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@