mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
buy torrent revert lock
This commit is contained in:
+10
-2
@@ -85,7 +85,7 @@ if ($redis->get("$torrentNotExistsKey:$info_hash")) {
|
|||||||
do_log("[ANNOUNCE] $msg");
|
do_log("[ANNOUNCE] $msg");
|
||||||
err($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])) {
|
if (!$isReAnnounce && !$redis->set($torrentReAnnounceKey, TIMENOW, ['nx', 'ex' => 60])) {
|
||||||
$msg = "Request too frequent(h)";
|
$msg = "Request too frequent(h)";
|
||||||
do_log(sprintf("[ANNOUNCE] %s key: %s already exists, value: %s", $msg, $torrentReAnnounceKey, TIMENOW));
|
do_log(sprintf("[ANNOUNCE] %s key: %s already exists, value: %s", $msg, $torrentReAnnounceKey, TIMENOW));
|
||||||
@@ -447,14 +447,22 @@ if (!isset($self))
|
|||||||
return intval($exists);
|
return intval($exists);
|
||||||
});
|
});
|
||||||
if (!$hasBuy) {
|
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();
|
$bonusRep = new \App\Repositories\BonusRepository();
|
||||||
try {
|
try {
|
||||||
$bonusRep->consumeToBuyTorrent($az['id'], $torrent['id'], 'Web');
|
$bonusRep->consumeToBuyTorrent($az['id'], $torrent['id'], 'Web');
|
||||||
$redis->set($hasBuyCacheKey, 1, $hasBuyCacheTime);
|
$redis->set($hasBuyCacheKey, 1, $hasBuyCacheTime);
|
||||||
|
$lock->release();
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$msg = $exception->getMessage();
|
$msg = $exception->getMessage();
|
||||||
do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg " . $exception->getTraceAsString(), 'error');
|
do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg " . $exception->getTraceAsString(), 'error');
|
||||||
err($msg);
|
warn($msg);
|
||||||
|
$lock->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user