buy torrent add lock for update + improve disabled func check

This commit is contained in:
xiaomlove
2023-06-02 02:45:15 +08:00
parent ff325ad687
commit 65eaf09a6d
4 changed files with 11 additions and 18 deletions

View File

@@ -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,

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.4');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-06-01');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-06-02');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -32,13 +32,11 @@ class Install
'UID_STARTS',
];
protected array $requiredExtensions = ['ctype', 'curl', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'bcmath', 'redis', 'gd', 'gmp', 'Zend OPcache'];
protected array $requiredExtensions = ['ctype', 'curl', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'bcmath', 'redis', 'gd', 'gmp', 'Zend OPcache', 'pcntl', 'posix', 'sockets'];
protected array $optionalExtensions = [
['name' => '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;
}

View File

@@ -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);