From 242857ffbe3c4e0cada61a49c69c17e5bb664f85 Mon Sep 17 00:00:00 2001 From: xiaomlove <1939737565@qq.com> Date: Thu, 7 Nov 2024 20:53:23 +0800 Subject: [PATCH] fix cleanup jobs --- app/Jobs/CalculateUserSeedBonus.php | 2 +- app/Jobs/UpdateTorrentSeedersEtc.php | 30 ++++++++++++------- app/Jobs/UpdateUserSeedingLeechingTime.php | 15 ++++++---- .../filament/widgets/stat-table.blade.php | 2 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/Jobs/CalculateUserSeedBonus.php b/app/Jobs/CalculateUserSeedBonus.php index 91dae9019..81b727086 100644 --- a/app/Jobs/CalculateUserSeedBonus.php +++ b/app/Jobs/CalculateUserSeedBonus.php @@ -142,7 +142,7 @@ public function handle() "update users set seed_points = case id %s end, seed_points_per_hour = case id %s end, seedbonus = case id %s end, seed_points_updated_at = '%s' where id in (%s)", implode(" ", $seedPointsUpdates), implode(" ", $seedPointsPerHourUpdates), implode(" ", $seedBonusUpdates), $nowStr, $idStr ); - $result = sql_query($sql); + $result = NexusDB::statement($sql); if ($delIdRedisKey) { NexusDB::cache_del($this->idRedisKey); } diff --git a/app/Jobs/UpdateTorrentSeedersEtc.php b/app/Jobs/UpdateTorrentSeedersEtc.php index 5234bd886..e2edcf8a0 100644 --- a/app/Jobs/UpdateTorrentSeedersEtc.php +++ b/app/Jobs/UpdateTorrentSeedersEtc.php @@ -78,18 +78,28 @@ public function handle() $torrentIdArr = explode(",", $idStr); //批量取,简单化 $torrents = array(); - $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder where torrent in ($idStr)"); - while ($row = mysql_fetch_assoc($res)) { - if ($row["seeder"] == "yes") +// $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder where torrent in ($idStr)"); + $res = NexusDB::table("peers") + ->selectRaw("torrent, seeder, COUNT(*) AS c") + ->whereRaw("torrent in ($idStr)") + ->groupBy(['torrent', 'seeder']) + ->get(); + foreach ($res as $row) { + if ($row->seeder == "yes") $key = "seeders"; else $key = "leechers"; - $torrents[$row["torrent"]][$key] = $row["c"]; + $torrents[$row->torrent][$key] = $row->c; } - $res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent where torrent in ($idStr)"); - while ($row = mysql_fetch_assoc($res)) { - $torrents[$row["torrent"]]["comments"] = $row["c"]; +// $res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent where torrent in ($idStr)"); + $res = NexusDB::table("comments") + ->selectRaw("torrent, COUNT(*) AS c") + ->whereRaw("torrent in ($idStr)") + ->groupBy(['torrent']) + ->get(); + foreach ($res as $row) { + $torrents[$row->torrent]["comments"] = $row["c"]; } $seedersUpdates = $leechersUpdates = $commentsUpdates = []; foreach ($torrentIdArr as $id) { @@ -101,14 +111,14 @@ public function handle() "update torrents set seeders = case id %s end, leechers = case id %s end, comments = case id %s end where id in (%s)", implode(" ", $seedersUpdates), implode(" ", $leechersUpdates), implode(" ", $commentsUpdates), $idStr ); - $result = sql_query($sql); + $result = NexusDB::statement($sql); if ($delIdRedisKey) { NexusDB::cache_del($this->idRedisKey); } $costTime = time() - $beginTimestamp; do_log(sprintf( - "$logPrefix, [DONE], update torrent count: %s, result: %s, cost time: %s seconds", - count($torrentIdArr), var_export($result, true), $costTime + "$logPrefix, [DONE], update torrent count: %s, result: %s, cost time: %s seconds, sql: %s", + count($torrentIdArr), var_export($result, true), $costTime, $sql )); } diff --git a/app/Jobs/UpdateUserSeedingLeechingTime.php b/app/Jobs/UpdateUserSeedingLeechingTime.php index 7226f16c9..7f69c2e13 100644 --- a/app/Jobs/UpdateUserSeedingLeechingTime.php +++ b/app/Jobs/UpdateUserSeedingLeechingTime.php @@ -76,20 +76,25 @@ public function handle() return; } //批量取,简单化 - $res = sql_query("select userid, sum(seedtime) as seedtime_sum, sum(leechtime) as leechtime_sum from snatched group by userid where userid in ($idStr)"); +// $res = sql_query("select userid, sum(seedtime) as seedtime_sum, sum(leechtime) as leechtime_sum from snatched group by userid where userid in ($idStr)"); + $res = NexusDB::table("snatched") + ->selectRaw("userid, sum(seedtime) as seedtime_sum, sum(leechtime) as leechtime_sum") + ->whereRaw("userid in ($idStr)") + ->groupBy("userid") + ->get(); $seedtimeUpdates = $leechTimeUpdates = []; $nowStr = now()->toDateTimeString(); $count = 0; - while ($row = mysql_fetch_assoc($res)) { + foreach ($res as $row) { $count++; - $seedtimeUpdates = sprintf("when %d then %d", $row['userid'], $row['seedtime_sum'] ?? 0); - $leechTimeUpdates = sprintf("when %d then %d", $row['userid'], $row['leechtime_sum'] ?? 0); + $seedtimeUpdates = sprintf("when %d then %d", $row->userid, $row->seedtime_sum ?? 0); + $leechTimeUpdates = sprintf("when %d then %d", $row->userid, $row->leechtime_sum ?? 0); } $sql = sprintf( "update users set seedtime = case id %s end, leechtime = case id %s end, seed_time_updated_at = '%s' where id in (%s)", implode(" ", $seedtimeUpdates), implode(" ", $leechTimeUpdates), $nowStr, $idStr ); - $result = sql_query($sql); + $result = NexusDB::statement($sql); if ($delIdRedisKey) { NexusDB::cache_del($this->idRedisKey); } diff --git a/resources/views/filament/widgets/stat-table.blade.php b/resources/views/filament/widgets/stat-table.blade.php index 4cb9e4f5e..770b861be 100644 --- a/resources/views/filament/widgets/stat-table.blade.php +++ b/resources/views/filament/widgets/stat-table.blade.php @@ -20,7 +20,7 @@ colspan="3" @endif > -