Skip to content

Commit

Permalink
announce add hr cache
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Sep 14, 2023
1 parent e82530c commit 4f919f6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions public/announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
Expand Down

0 comments on commit 4f919f6

Please sign in to comment.