mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
fix magic.php + improve TrackerUrl::getById()
This commit is contained in:
@@ -60,13 +60,36 @@ class TrackerUrl extends NexusModel
|
||||
public static function getById(int $trackerUrlId)
|
||||
{
|
||||
$redis = NexusDB::redis();
|
||||
$notFoundFlagKey = "TRACKER_URL_NOT_FOUND:$trackerUrlId";
|
||||
if ($trackerUrlId == 0) {
|
||||
return $redis->get(self::TRACKER_URL_DEFAULT_CACHE_KEY);
|
||||
return self::getFromRedisWithRetry($redis, 'get', [self::TRACKER_URL_DEFAULT_CACHE_KEY], $notFoundFlagKey);
|
||||
}
|
||||
$result = $redis->hget(self::TRACKER_URL_CACHE_KEY, $trackerUrlId);
|
||||
if (!$result) {
|
||||
$result = $redis->get(self::TRACKER_URL_DEFAULT_CACHE_KEY);
|
||||
$result = self::getFromRedisWithRetry($redis, 'hGet', [self::TRACKER_URL_CACHE_KEY, $trackerUrlId], $notFoundFlagKey);
|
||||
if ($result !== false) {
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
do_log("No tracker url found for $trackerUrlId, try default", 'warning');
|
||||
return self::getFromRedisWithRetry($redis, 'get', [self::TRACKER_URL_DEFAULT_CACHE_KEY], $notFoundFlagKey);
|
||||
}
|
||||
|
||||
private static function getFromRedisWithRetry(\Redis $redis, string $command, array $params, string $notFoundFlagKey)
|
||||
{
|
||||
$result = call_user_func_array([$redis, $command], $params);
|
||||
if ($result !== false) {
|
||||
return $result;
|
||||
}
|
||||
//有不存在标记,不要再尝试,直接返回 false
|
||||
if ($redis->exists($notFoundFlagKey)) {
|
||||
return false;
|
||||
}
|
||||
self::saveUrlCache();
|
||||
$result = call_user_func_array([$redis, $command], $params);
|
||||
if ($result !== false) {
|
||||
return $result;
|
||||
}
|
||||
//只从 db 拉取一次,仍然没有即标记不存在, 有效期 15 分钟
|
||||
$redis->setex($notFoundFlagKey, 900, date("Y-m-d H:i:s"));
|
||||
do_log(sprintf("redis command %s with args %s no result", $command, json_encode($params)), 'error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.7');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-09-24');
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.8');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-10-01');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
+2
-3
@@ -17,9 +17,7 @@ if (!$arr) exit(json_encode(fail("Invalid torrent id!", $_POST)));
|
||||
|
||||
$torrentowner = $arr['owner'];
|
||||
if($torrentowner == $userid) exit(json_encode(fail('You are giving magic to yourself.', $_POST)));
|
||||
$tsql = sql_query("SELECT COUNT(*) FROM magic WHERE torrentid=$torrentid and userid=$userid") or sqlerr(__FILE__,__LINE__);
|
||||
$trows = mysql_fetch_assoc($tsql);
|
||||
$t_ab = $trows[0];
|
||||
$t_ab = get_row_count("magic", "WHERE torrentid=$torrentid and userid=$userid");
|
||||
if ($t_ab != 0) exit(json_encode(fail("You already gave the magic value!", $_POST)));
|
||||
$todayStr = now()->startOfDay();
|
||||
$todayCount = \App\Models\Reward::query()
|
||||
@@ -38,4 +36,5 @@ if (isset($userid) && isset($torrentid)&& isset($value)) {
|
||||
\App\Models\BonusLogs::add($CURUSER['id'], $CURUSER['seedbonus'], $value, $CURUSER['seedbonus'] - $value, "", \App\Models\BonusLogs::BUSINESS_TYPE_REWARD_TORRENT);
|
||||
KPS("+",$value,$torrentowner);//add to the owner
|
||||
\App\Models\BonusLogs::add($torrentOwnerInfo['id'], $torrentOwnerInfo['seedbonus'], $value, $torrentOwnerInfo['seedbonus'] + $value, "", \App\Models\BonusLogs::BUSINESS_TYPE_TORRENT_BE_REWARD);
|
||||
exit(json_encode(success("OK", $_POST)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user