From 4f919f677d098b6a92367c682dab886712872df1 Mon Sep 17 00:00:00 2001 From: lgb <353856593@qq.com> Date: Thu, 14 Sep 2023 15:06:17 +0800 Subject: [PATCH] announce add hr cache --- public/announce.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/public/announce.php b/public/announce.php index 25882234c..b2ee47d44 100644 --- a/public/announce.php +++ b/public/announce.php @@ -660,9 +660,15 @@ if ($includeHr) { $hrMode = \App\Models\HitAndRun::getConfig('mode', $torrent['mode']); if ($hrMode == \App\Models\HitAndRun::MODE_GLOBAL || ($hrMode == \App\Models\HitAndRun::MODE_MANUAL && $torrent['hr'] == \App\Models\Torrent::HR_YES)) { - $sql = "insert into hit_and_runs (uid, torrent_id, snatched_id) values ($userid, $torrentid, {$snatchInfo['id']}) on duplicate key update updated_at = " . sqlesc(date('Y-m-d H:i:s')); - $affectedRows = sql_query($sql); - do_log("[INSERT_H&R], $sql, affectedRows: $affectedRows"); + $hrCacheKey = sprintf("hit_and_run:%d:%d", $userid, $torrentid); + $hrExists = \Nexus\Database\NexusDB::remember($hrCacheKey, 24*3600, function () use ($snatchInfo) { + return \App\Models\HitAndRun::query()->where("snatched_id", $snatchInfo['id'])->exists(); + }); + if (!$hrExists) { + $sql = "insert into hit_and_runs (uid, torrent_id, snatched_id) values ($userid, $torrentid, {$snatchInfo['id']}) on duplicate key update updated_at = " . sqlesc(date('Y-m-d H:i:s')); + $affectedRows = sql_query($sql); + do_log("[INSERT_H&R], $sql, affectedRows: $affectedRows"); + } } } }