From 3db45371535177c505500b4372f56f08b1703e99 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Tue, 17 Jun 2025 20:54:18 +0700 Subject: [PATCH] improve paid torrent + hit and run --- app/Console/Commands/Test.php | 9 +- .../Upgrade/MigrateSnatchedHitAndRunId.php | 31 +++++++ .../Upgrade/UpdateSnatchedBuyLogId.php | 31 +++++++ app/Console/Kernel.php | 2 +- app/Enums/ModelEventEnum.php | 6 ++ app/Events/SnatchedUpdated.php | 41 ++++++++++ app/Jobs/BuyTorrent.php | 14 ++-- app/Jobs/UpdateUserDownloadPrivilege.php | 30 +++++++ app/Models/Snatch.php | 2 +- app/Repositories/BonusRepository.php | 10 +-- app/Repositories/CleanupRepository.php | 3 + app/Repositories/TorrentRepository.php | 49 +++++++++-- ...12_add_hr_and_buy_id_to_snatched_table.php | 29 +++++++ include/cleanup.php | 27 +++++- include/constants.php | 2 +- include/globalfunctions.php | 2 - nexus/Install/Update.php | 9 ++ nexus/Nexus.php | 1 + public/announce.php | 82 ++++++++++--------- public/takeupdate.php | 3 + public/torrents.php | 13 ++- 21 files changed, 326 insertions(+), 70 deletions(-) create mode 100644 app/Console/Commands/Upgrade/MigrateSnatchedHitAndRunId.php create mode 100644 app/Console/Commands/Upgrade/UpdateSnatchedBuyLogId.php create mode 100644 app/Events/SnatchedUpdated.php create mode 100644 app/Jobs/UpdateUserDownloadPrivilege.php create mode 100644 database/migrations/2025_06_09_222012_add_hr_and_buy_id_to_snatched_table.php diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 2cf04831..f070f86f 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use App\Jobs\CheckQueueFailedJobs; use App\Jobs\SettleClaim; +use App\Jobs\UpdateUserDownloadPrivilege; use App\Models\ExamUser; use App\Models\Language; use App\Models\PersonalAccessToken; @@ -61,7 +62,7 @@ class Test extends Command */ public function handle() { -// $failedJob = DB::table('failed_jobs')->find(555); +// $failedJob = DB::table('failed_jobs')->find(569); // // $payload = json_decode($failedJob->payload, true); // dd($payload); @@ -71,7 +72,11 @@ class Test extends Command // // dd($job); - CheckQueueFailedJobs::dispatch(); +// UpdateUserDownloadPrivilege::dispatch(1, "yes", "test_key"); +// $res = unserialize("O:36:\"App\\Jobs\\UpdateUserDownloadPrivilege\":3:{s:6:\"userId\";i:1;s:6:\"status\";s:3:\"yes\";s:9:\"reasonKey\";s:8:\"test_key\";}"); +// $res = unserialize("O:36:\"App\\Jobs\\UpdateUserDownloadPrivilege\":3:{s:6:\"userId\";i:1;s:6:\"status\";s:3:\"yes\";s:9:\"reasonKey\";s:8:\"test_key\";}"); +// dd($res); + UpdateUserDownloadPrivilege::dispatch(1, "yes", "test_key"); } } diff --git a/app/Console/Commands/Upgrade/MigrateSnatchedHitAndRunId.php b/app/Console/Commands/Upgrade/MigrateSnatchedHitAndRunId.php new file mode 100644 index 00000000..e4a85254 --- /dev/null +++ b/app/Console/Commands/Upgrade/MigrateSnatchedHitAndRunId.php @@ -0,0 +1,31 @@ +command('meilisearch:import')->weeklyOn(1, "03:00"); $schedule->command('torrent:load_pieces_hash')->dailyAt("01:00"); $schedule->job(new CheckQueueFailedJobs())->everySixHours(); - $schedule->job(new ThirdPartyJob())->everyMinute(); +// $schedule->job(new ThirdPartyJob())->everyMinute(); $schedule->job(new MaintainPluginState())->everyMinute(); $schedule->job(new UpdateIsSeedBoxFromUserRecordsCache())->everySixHours(); $schedule->job(new CheckCleanup())->everyFifteenMinutes(); diff --git a/app/Enums/ModelEventEnum.php b/app/Enums/ModelEventEnum.php index 32de3dd6..f627d2ce 100644 --- a/app/Enums/ModelEventEnum.php +++ b/app/Enums/ModelEventEnum.php @@ -3,6 +3,7 @@ namespace App\Enums; use App\Events\NewsCreated; +use App\Events\SnatchedUpdated; use App\Events\TorrentCreated; use App\Events\TorrentDeleted; use App\Events\TorrentUpdated; @@ -12,6 +13,7 @@ use App\Events\UserDisabled; use App\Events\UserEnabled; use App\Events\UserUpdated; use App\Models\News; +use App\Models\Snatch; use App\Models\Torrent; use App\Models\User; @@ -28,6 +30,8 @@ final class ModelEventEnum { const NEWS_CREATED = 'news_created'; + const SNATCHED_UPDATED = 'snatched_updated'; + public static array $eventMaps = [ self::TORRENT_CREATED => ['event' => TorrentCreated::class, 'model' => Torrent::class], self::TORRENT_UPDATED => ['event' => TorrentUpdated::class, 'model' => Torrent::class], @@ -40,5 +44,7 @@ final class ModelEventEnum { self::USER_DISABLED => ['event' => UserDisabled::class, 'model' => User::class], self::NEWS_CREATED => ['event' => NewsCreated::class, 'model' => News::class], + + self::SNATCHED_UPDATED => ['event' => SnatchedUpdated::class, 'model' => Snatch::class], ]; } diff --git a/app/Events/SnatchedUpdated.php b/app/Events/SnatchedUpdated.php new file mode 100644 index 00000000..4b12620c --- /dev/null +++ b/app/Events/SnatchedUpdated.php @@ -0,0 +1,41 @@ +model = $model; + } + + /** + * Get the channels the event should broadcast on. + * + * @return array + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/app/Jobs/BuyTorrent.php b/app/Jobs/BuyTorrent.php index 258a221b..f866abf0 100644 --- a/app/Jobs/BuyTorrent.php +++ b/app/Jobs/BuyTorrent.php @@ -34,6 +34,7 @@ class BuyTorrent implements ShouldQueue * Execute the job. * * @return void + * @throws \Throwable */ public function handle() { @@ -42,27 +43,28 @@ class BuyTorrent implements ShouldQueue $userId = $this->userId; $torrentId = $this->torrentId; - $hasBuy = TorrentBuyLog::query() + $buyLog = TorrentBuyLog::query() ->where("uid", $userId) ->where("torrent_id", $torrentId) - ->exists() + ->first(); ; - if ($hasBuy) { + if ($buyLog) { //标记购买成功 do_log("$logPrefix, already bought"); - $torrentRep->addBuySuccessCache($userId, $torrentId); + $torrentRep->addBuySuccessCache($userId, $torrentId, $buyLog->id); return; } try { $bonusRep = new BonusRepository(); - $bonusRep->consumeToBuyTorrent($this->userId, $this->torrentId); + $buyLog = $bonusRep->consumeToBuyTorrent($this->userId, $this->torrentId); //标记购买成功 do_log("$logPrefix, buy torrent success"); - $torrentRep->addBuySuccessCache($userId, $torrentId); + $torrentRep->addBuySuccessCache($userId, $torrentId, $buyLog->id); } catch (\Throwable $throwable) { //标记购买失败,缓存 3600 秒,这个时间内不能再次购买 do_log("$logPrefix, buy torrent fail: " . $throwable->getMessage(), "error"); $torrentRep->addBuyFailCache($userId, $torrentId); + throw $throwable; } } } diff --git a/app/Jobs/UpdateUserDownloadPrivilege.php b/app/Jobs/UpdateUserDownloadPrivilege.php new file mode 100644 index 00000000..f61eab17 --- /dev/null +++ b/app/Jobs/UpdateUserDownloadPrivilege.php @@ -0,0 +1,30 @@ +updateDownloadPrivileges(null, $this->userId, $this->status, $this->reasonKey); + do_log("Updating user download privilege for user {$this->userId} to {$this->status} by reason {$this->reasonKey}"); + } +} diff --git a/app/Models/Snatch.php b/app/Models/Snatch.php index 730b5630..a559ddb0 100644 --- a/app/Models/Snatch.php +++ b/app/Models/Snatch.php @@ -13,7 +13,7 @@ class Snatch extends NexusModel protected $fillable = [ 'torrentid', 'userid', 'ip', 'port', 'uploaded', 'downloaded', 'to_go', 'seedtime', 'leechtime', - 'last_action', 'startdat', 'completedat', 'finished' + 'last_action', 'startdat', 'completedat', 'finished', 'hit_and_run_id', 'buy_log_id', ]; protected $casts = [ diff --git a/app/Repositories/BonusRepository.php b/app/Repositories/BonusRepository.php index ba7f6327..81c89c1f 100644 --- a/app/Repositories/BonusRepository.php +++ b/app/Repositories/BonusRepository.php @@ -252,11 +252,11 @@ class BonusRepository extends BaseRepository } - public function consumeToBuyTorrent($uid, $torrentId, $channel = 'Web'): bool + public function consumeToBuyTorrent($uid, $torrentId, $channel = 'Web'): TorrentBuyLog { $torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields); $requireBonus = $torrent->price; - NexusDB::transaction(function () use ($requireBonus, $torrent, $channel, $uid) { + return NexusDB::transaction(function () use ($requireBonus, $torrent, $channel, $uid) { $userQuery = User::query(); if ($requireBonus > 0) { $userQuery = $userQuery->lockForUpdate(); @@ -269,7 +269,7 @@ class BonusRepository extends BaseRepository ], $buyerLocale); do_log("comment: $comment"); $this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_TORRENT, $comment); - TorrentBuyLog::query()->create([ + $buyLog = TorrentBuyLog::query()->create([ 'uid' => $user->id, 'torrent_id' => $torrent->id, 'price' => $requireBonus, @@ -314,10 +314,8 @@ class BonusRepository extends BaseRepository ], $buyerLocale), ]; Message::add($buyTorrentSuccessMessage); + return $buyLog; }); - - return true; - } public function consumeUserBonus($user, $requireBonus, $logBusinessType, $logComment = '', array $userUpdates = []) diff --git a/app/Repositories/CleanupRepository.php b/app/Repositories/CleanupRepository.php index d954ff45..3222c11b 100644 --- a/app/Repositories/CleanupRepository.php +++ b/app/Repositories/CleanupRepository.php @@ -257,6 +257,9 @@ LUA; "lastcleantime5" => "five", ]; $avps = Avp::query()->get()->keyBy("arg"); + if ($avps->isEmpty()) { + return; + } foreach ($arvToLevel as $arg => $level) { /** @var NexusModel $value */ $value = $avps->get($arg); diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index e9a61377..949298f3 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -3,6 +3,7 @@ namespace App\Repositories; use App\Auth\Permission; +use App\Enums\ModelEventEnum; use App\Exceptions\InsufficientPermissionException; use App\Exceptions\NexusException; use App\Http\Resources\TorrentResource; @@ -843,20 +844,51 @@ HTML; } /** - * 购买成功缓存,保存为 hash,一个种子一个 hash,永久有效 + * 购买成功,缓存 30 天并更新到 snatched 上 * @param $uid * @param $torrentId * @return void * @throws \RedisException */ - public function addBuySuccessCache($uid, $torrentId): void + public function addBuySuccessCache($uid, $torrentId, $buyLogId): void { - NexusDB::redis()->hSet($this->getBoughtUserCacheKey($torrentId), $uid, 1); + NexusDB::redis()->set($this->getBoughtUserCacheKey($torrentId, $uid), 1, ['NX', 'EX' => 86400*30]); + $record = Snatch::query() + ->where("torrentid", $torrentId) + ->where("userid", $uid) + ->first(); + if ($record) { + $record->buy_log_id = $buyLogId; + $record->save(); + publish_model_event(ModelEventEnum::SNATCHED_UPDATED, $record->id); + } else { + do_log("addBuySuccessCache, uid: $uid, torrentId: $torrentId, buyLogId: $buyLogId, snatched not exists", 'error'); + } + } public function hasBuySuccessCache($uid, $torrentId): bool { - return NexusDB::redis()->hGet($this->getBoughtUserCacheKey($torrentId), $uid) == 1; + $key = $this->getBoughtUserCacheKey($torrentId, $uid); + if (NexusDB::redis()->exists($key)) { + return true; + } + return false; + } + + public function hasBuySuccess($uid, $torrentId): bool + { + if ($this->hasBuySuccessCache($uid, $torrentId)) { + return true; + } + $buyLog = TorrentBuyLog::query() + ->where("torrent_id", $torrentId) + ->where("uid", $uid) + ->first(); + if ($buyLog) { + $this->addBuySuccessCache($uid, $torrentId, $buyLog->id); + } + return $buyLog != null; } /** @@ -868,8 +900,8 @@ HTML; */ public function getBuyStatus($uid, $torrentId): int { - //查询是否已经购买 - if ($this->hasBuySuccessCache($uid, $torrentId)) { + //从缓存中判断是否购买过 + if ($this->hasBuySuccess($uid, $torrentId)) { return self::BUY_STATUS_SUCCESS; } //是否购买失败过 @@ -913,12 +945,13 @@ HTML; /** * 购买成功缓存 key + * @update 改为使用字符串判断键是否存在即可 * @param $torrentId * @return string */ - public function getBoughtUserCacheKey($torrentId): string + public function getBoughtUserCacheKey($torrentId, $userId): string { - return sprintf("%s:%s", self::BOUGHT_USER_CACHE_KEY_PREFIX, $torrentId); + return sprintf("%s:%s:%s", self::BOUGHT_USER_CACHE_KEY_PREFIX, $torrentId, $userId); } /** diff --git a/database/migrations/2025_06_09_222012_add_hr_and_buy_id_to_snatched_table.php b/database/migrations/2025_06_09_222012_add_hr_and_buy_id_to_snatched_table.php new file mode 100644 index 00000000..ed52038d --- /dev/null +++ b/database/migrations/2025_06_09_222012_add_hr_and_buy_id_to_snatched_table.php @@ -0,0 +1,29 @@ +bigInteger("hit_and_run_id")->default(0); + $table->bigInteger("buy_log_id")->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('snatched', function (Blueprint $table) { + $table->dropColumn("hit_and_run_id", "buy_log_id"); + }); + } +}; diff --git a/include/cleanup.php b/include/cleanup.php index 1d057b0f..b52b5c8c 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -1,6 +1,8 @@ whereIn('id', $uidArr)->update($update); \App\Models\UserBanLog::query()->insert($userBanLogData); do_log("ban user: " . implode(', ', $uidArr)); + foreach ($uidArr as $uid) { + publish_model_event(ModelEventEnum::USER_UPDATED, $uid); + } return $uidArr; } @@ -241,6 +259,9 @@ function disable_user(\Illuminate\Database\Eloquent\Builder $query, $reasonKey) \App\Models\UserBanLog::query()->insert($userBanLogData); \App\Models\UserModifyLog::query()->insert($userModifyLogs); do_log("[DISABLE_USER]($reasonKey): " . implode(', ', $uidArr)); + foreach ($uidArr as $uid) { + publish_model_event(ModelEventEnum::USER_DISABLED, $uid); + } return $uidArr; } @@ -494,8 +515,8 @@ function docleanup($forceAll = 0, $printProgress = false) { torrent_promotion_expire($expirenormal_torrent, 1, $normalbecome_torrent); //expire individual torrent promotion - sql_query("UPDATE torrents SET sp_state = 1, promotion_time_type=0, promotion_until=null WHERE promotion_time_type=2 AND promotion_until < ".sqlesc(date("Y-m-d H:i:s",TIMENOW))) or sqlerr(__FILE__, __LINE__); - +// sql_query("UPDATE torrents SET sp_state = 1, promotion_time_type=0, promotion_until=null WHERE promotion_time_type=2 AND promotion_until < ".sqlesc(date("Y-m-d H:i:s",TIMENOW))) or sqlerr(__FILE__, __LINE__); + torrent_promotion_individual_expire(); //End: expire torrent promotion $log = "expire torrent promotion"; do_log($log); @@ -734,6 +755,7 @@ function docleanup($forceAll = 0, $printProgress = false) { sql_query("UPDATE users SET class = '1', vip_added = 'no', vip_until = null WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, $dt, $msg, $subject)") or sqlerr(__FILE__, __LINE__); } + publish_model_event(ModelEventEnum::USER_UPDATED, $arr['id']); } } if (!empty($userModifyLogs)) { @@ -764,6 +786,7 @@ function docleanup($forceAll = 0, $printProgress = false) { ]; sql_query("UPDATE users SET donor = 'no' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, $dt, $msg, $subject)") or sqlerr(__FILE__, __LINE__); + publish_model_event(ModelEventEnum::USER_UPDATED, $arr['id']); } } if (!empty($userModifyLogs)) { diff --git a/include/constants.php b/include/constants.php index c4ab8af0..3653dd8c 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ runMigrate("database/migrations/2025_06_09_222012_add_hr_and_buy_id_to_snatched_table.php"); + Artisan::call("upgrade:migrate_snatched_hr_id"); + Artisan::call("upgrade:migrate_snatched_buy_log_id"); + } + } public function runExtraMigrate() diff --git a/nexus/Nexus.php b/nexus/Nexus.php index d29b4be5..281b5892 100644 --- a/nexus/Nexus.php +++ b/nexus/Nexus.php @@ -422,6 +422,7 @@ final class Nexus public static function dispatchQueueJob(ShouldQueue $job): void { self::getQueueManager()->connection(self::QUEUE_CONNECTION_NAME)->push($job); + do_log("dispatchQueueJob: " . nexus_json_encode($job)); } diff --git a/public/announce.php b/public/announce.php index a721a7f8..d248d9dc 100644 --- a/public/announce.php +++ b/public/announce.php @@ -347,6 +347,46 @@ $log .= ", [SEED_BOX], isSeedBoxRuleEnabled: $isSeedBoxRuleEnabled, isIPSeedBox: do_log($log); +//handle paid torrent +if ( + $seeder == 'no' + && isset($az['seedbonus']) + && isset($torrent['price']) + && $torrent['price'] > 0 + && $torrent['owner'] != $userid + && get_setting("torrent.paid_torrent_enabled") == "yes" +) { + $torrentRep = new \App\Repositories\TorrentRepository(); + $buyStatus = $torrentRep->getBuyStatus($userid, $torrentid); + do_log("user: $userid buy torrent: $torrentid, status: $buyStatus"); + if ($buyStatus > 0) { + do_log(sprintf("user: %s buy torrent: %s fail count: %s", $userid, $torrentid, $buyStatus), "error"); + if ($buyStatus > 3) { + //warn + \App\Utils\MsgAlert::getInstance()->add( + "announce_paid_torrent_too_many_times", + time() + 86400, + "announce to paid torrent and fail too many times, please make sure you have enough bonus!", + "", + "black" + ); + } + if ($buyStatus > 10) { + //disable download + (new \App\Repositories\UserRepository())->updateDownloadPrivileges(null, $userid, 'no', 'announce_paid_torrent_too_many_times'); + } + \Nexus\Nexus::dispatchQueueJob(new \App\Jobs\BuyTorrent($userid, $torrentid)); + //already fail, add fail times + $torrentRep->addBuyFailCache($userid, $torrentid); + warn("purchase in progress, please try again later, and make sure you have enough bonus", 300); + } + if ($buyStatus == \App\Repositories\TorrentRepository::BUY_STATUS_UNKNOWN) { + //just enqueue job + \Nexus\Nexus::dispatchQueueJob(new \App\Jobs\BuyTorrent($userid, $torrentid)); + warn("purchase started, please wait", 300); + } +} + // current peer_id, or you could say session with tracker not found in table peers if (!isset($self)) { @@ -393,42 +433,6 @@ if (!isset($self)) } } } - if ( - $seeder == 'no' - && isset($az['seedbonus']) - && isset($torrent['price']) - && $torrent['price'] > 0 - && $torrent['owner'] != $userid - && get_setting("torrent.paid_torrent_enabled") == "yes" - ) { - $torrentRep = new \App\Repositories\TorrentRepository(); - $buyStatus = $torrentRep->getBuyStatus($userid, $torrentid); - if ($buyStatus > 0) { - do_log(sprintf("user: %v buy torrent: %v fail count: %v", $userid, $torrentid, $buyStatus), "error"); - if ($buyStatus > 3) { - //warn - \App\Utils\MsgAlert::getInstance()->add( - "announce_paid_torrent_too_many_times", - time() + 86400, - "announce to paid torrent and fail too many times, please make sure you have enough bonus!", - "", - "black" - ); - } - if ($buyStatus > 10) { - //disable download - (new \App\Repositories\UserRepository())->updateDownloadPrivileges(null, $userid, 'no', 'announce_paid_torrent_too_many_times'); - } - //already fail, add fail times - $torrentRep->addBuyFailCache($userid, $torrentid); - warn("purchase fail, please try again later, please make sure you have enough bonus", 300); - } - if ($buyStatus == \App\Repositories\TorrentRepository::BUY_STATUS_UNKNOWN) { - //just enqueue job - \App\Utils\ThirdPartyJob::addBuyTorrent($userid, $torrentid); - warn("purchase in progress, please wait", 300); - } - } } else // continue an existing session { @@ -567,7 +571,11 @@ if (($left > 0 || $event == "completed") && $az['class'] < \App\Models\HitAndRun $userid, $torrentid, $snatchInfo['id'], $nowStr, $nowStr, $nowStr ); $affectedRows = sql_query($sql); - do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} >= required: $requiredDownloaded, [INSERT_H&R], sql: $sql, affectedRows: $affectedRows"); + $hitAndRunId = mysql_insert_id(); + do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} >= required: $requiredDownloaded, [INSERT_H&R], sql: $sql, affectedRows: $affectedRows, hitAndRunId: $hitAndRunId"); + if ($hitAndRunId > 0) { + sql_query("update snatched set hit_and_run_id = $hitAndRunId where id = {$snatchInfo['id']}"); + } } else { do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} < required: $requiredDownloaded", "debug"); } diff --git a/public/takeupdate.php b/public/takeupdate.php index 332bc519..6d9cafba 100644 --- a/public/takeupdate.php +++ b/public/takeupdate.php @@ -9,6 +9,9 @@ function bark($msg) { dbconn(); loggedinorreturn(); user_can('staffmem', true); +if (empty($_POST['delreport'])) { + stderr('Error', $lang_functions['select_at_least_one_record']); +} if ($_POST['setdealt']){ $res = sql_query ("SELECT id FROM reports WHERE dealtwith=0 AND id IN (" . implode(", ", $_POST['delreport']) . ")"); while ($arr = mysql_fetch_assoc($res)) diff --git a/public/torrents.php b/public/torrents.php index c01502ba..e02986d4 100644 --- a/public/torrents.php +++ b/public/torrents.php @@ -769,7 +769,8 @@ if (isset($searchstr)) case 1 : // torrent description { foreach ($like_expression_array as &$like_expression_array_element) - $like_expression_array_element = "torrents.descr". $like_expression_array_element; +// $like_expression_array_element = "torrents.descr". $like_expression_array_element; + $like_expression_array_element = "torrent_extras.descr". $like_expression_array_element; $wherea[] = implode($ANDOR, $like_expression_array); break; } @@ -913,12 +914,16 @@ if ($tagId > 0) { $tagFilter = " inner join torrent_tags on torrents.id = torrent_tags.torrent_id and torrent_tags.tag_id = $tagId "; $addparam .= "tag_id={$tagId}&"; } +$torrentExtraFilter = ""; +if ($search_area == 1) { + $torrentExtraFilter = " inner join torrent_extras on torrents.id = torrent_extras.torrent_id "; +} if ($allsec == 1 || $enablespecial != 'yes') { if ($where != "") $where = "WHERE $where "; else $where = ""; - $sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where; + $sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $torrentExtraFilter . $where; } else { @@ -930,7 +935,7 @@ else $where = "WHERE $where"; else $where = ""; // $sql = "SELECT COUNT(*), categories.mode FROM torrents LEFT JOIN categories ON category = categories.id " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where . " GROUP BY categories.mode"; - $sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where; + $sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $torrentExtraFilter . $where; } if ($shouldUseMeili) { @@ -986,7 +991,7 @@ if ($count) // $query = "SELECT $fieldsStr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." $tagFilter $where $orderby $limit"; // } else { // $query = "SELECT $fieldsStr, categories.mode as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." LEFT JOIN categories ON torrents.category=categories.id $tagFilter $where $orderby $limit"; - $query = "SELECT $fieldsStr, $sectiontype as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")."$tagFilter $where $orderby $limit"; + $query = "SELECT $fieldsStr, $sectiontype as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")."$tagFilter $torrentExtraFilter $where $orderby $limit"; // } do_log("[TORRENT_LIST_SQL] $query", 'debug'); if (!$shouldUseMeili) {