diff --git a/app/Repositories/BonusRepository.php b/app/Repositories/BonusRepository.php index 2d73285e..798e6956 100644 --- a/app/Repositories/BonusRepository.php +++ b/app/Repositories/BonusRepository.php @@ -254,10 +254,14 @@ class BonusRepository extends BaseRepository public function consumeToBuyTorrent($uid, $torrentId, $channel = 'Web'): bool { - $user = User::query()->findOrFail($uid); $torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields); $requireBonus = $torrent->price; - NexusDB::transaction(function () use ($user, $requireBonus, $torrent, $channel) { + NexusDB::transaction(function () use ($requireBonus, $torrent, $channel, $uid) { + $userQuery = User::query(); + if ($requireBonus > 0) { + $userQuery = $userQuery->lockForUpdate(); + } + $user = $userQuery->findOrFail($uid); $comment = nexus_trans('bonus.comment_buy_torrent', [ 'bonus' => $requireBonus, 'torrent_id' => $torrent->id, diff --git a/include/constants.php b/include/constants.php index 9f0d96fe..2f6ca79a 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ 'pcntl', 'desc' => "If use Octane and 'Current' showing 0, make sure it's on php -m"], - ['name' => 'posix', 'desc' => "If use Octane and 'Current' showing 0, make sure it's on php -m"], - ['name' => 'sockets', 'desc' => "If use roadrunner for Octane, make sure 'current' shows 1"], - ['name' => 'swoole', 'desc' => "If use swoole for Octane, make sure 'current' shows 1"], +// ['name' => 'swoole', 'desc' => "If use swoole for Octane, make sure 'current' shows 1"], ]; + protected array $requiredFunctions = ['symlink', 'putenv', 'proc_open', 'proc_get_status', 'exec', 'pcntl_signal', 'pcntl_alarm', 'pcntl_async_signals']; protected string $lockFile = 'install.lock'; @@ -165,9 +163,8 @@ class Install 'result' => $this->yesOrNo(version_compare(PHP_VERSION, $this->minimumPhpVersion, '>=')), ]; - $requiredFunctions = ['symlink', 'putenv', 'proc_open', 'proc_get_status', 'exec']; $disabledFunctions = []; - foreach ($requiredFunctions as $fn) { + foreach ($this->requiredFunctions as $fn) { if (!function_exists($fn)) { $disabledFunctions[] = $fn; } diff --git a/public/announce.php b/public/announce.php index 2085b59c..206c3c4c 100644 --- a/public/announce.php +++ b/public/announce.php @@ -224,19 +224,11 @@ if ( return intval($exists); }); if (!$hasBuy) { - $lock = new \Nexus\Database\NexusLock("buying_torrent:$userid", 10); - if (!$lock->get()) { - $msg = "buying torrent, wait!"; - do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg", 'error'); - err($msg); - } $bonusRep = new \App\Repositories\BonusRepository(); try { $bonusRep->consumeToBuyTorrent($az['id'], $torrent['id'], 'Web'); - $lock->release(); $redis->set($hasBuyCacheKey, 1, $hasBuyCacheTime); } catch (\Exception $exception) { - $lock->release(); $msg = $exception->getMessage(); do_log("[ANNOUNCE] user: $userid, torrent: $torrentid, $msg " . $exception->getTraceAsString(), 'error'); err($msg);