From 6742ae4aeedfe33854d9157eead2480a56aa133f Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 5 Jun 2023 03:02:04 +0800 Subject: [PATCH] buy torrent revert lock --- public/announce.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/public/announce.php b/public/announce.php index 62af9a45..153c5bfc 100644 --- a/public/announce.php +++ b/public/announce.php @@ -85,7 +85,7 @@ if ($redis->get("$torrentNotExistsKey:$info_hash")) { do_log("[ANNOUNCE] $msg"); err($msg); } -$torrentReAnnounceKey = sprintf('reAnnounceCheckByPasskey:%s:%s', $userAuthenticateKey, $info_hash); +$torrentReAnnounceKey = sprintf('reAnnounceCheckByInfoHash:%s:%s', $userAuthenticateKey, $info_hash); if (!$isReAnnounce && !$redis->set($torrentReAnnounceKey, TIMENOW, ['nx', 'ex' => 60])) { $msg = "Request too frequent(h)"; do_log(sprintf("[ANNOUNCE] %s key: %s already exists, value: %s", $msg, $torrentReAnnounceKey, TIMENOW)); @@ -447,14 +447,22 @@ if (!isset($self)) return intval($exists); }); if (!$hasBuy) { + $lock = new \Nexus\Database\NexusLock("buying_torrent:$userid", 5); + if (!$lock->get()) { + $msg = "buying torrent, wait!"; + do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg", 'error'); + warn($msg); + } $bonusRep = new \App\Repositories\BonusRepository(); try { $bonusRep->consumeToBuyTorrent($az['id'], $torrent['id'], 'Web'); $redis->set($hasBuyCacheKey, 1, $hasBuyCacheTime); + $lock->release(); } catch (\Exception $exception) { $msg = $exception->getMessage(); do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg " . $exception->getTraceAsString(), 'error'); - err($msg); + warn($msg); + $lock->release(); } } }