Skip to content

Commit

Permalink
fix cleanup jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Nov 7, 2024
1 parent f1af33c commit 242857f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/Jobs/CalculateUserSeedBonus.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function handle()
"update users set seed_points = case id %s end, seed_points_per_hour = case id %s end, seedbonus = case id %s end, seed_points_updated_at = '%s' where id in (%s)",
implode(" ", $seedPointsUpdates), implode(" ", $seedPointsPerHourUpdates), implode(" ", $seedBonusUpdates), $nowStr, $idStr
);
$result = sql_query($sql);
$result = NexusDB::statement($sql);
if ($delIdRedisKey) {
NexusDB::cache_del($this->idRedisKey);
}
Expand Down
30 changes: 20 additions & 10 deletions app/Jobs/UpdateTorrentSeedersEtc.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,28 @@ public function handle()
$torrentIdArr = explode(",", $idStr);
//批量取,简单化
$torrents = array();
$res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder where torrent in ($idStr)");
while ($row = mysql_fetch_assoc($res)) {
if ($row["seeder"] == "yes")
// $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder where torrent in ($idStr)");
$res = NexusDB::table("peers")
->selectRaw("torrent, seeder, COUNT(*) AS c")
->whereRaw("torrent in ($idStr)")
->groupBy(['torrent', 'seeder'])
->get();
foreach ($res as $row) {
if ($row->seeder == "yes")
$key = "seeders";
else
$key = "leechers";
$torrents[$row["torrent"]][$key] = $row["c"];
$torrents[$row->torrent][$key] = $row->c;
}

$res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent where torrent in ($idStr)");
while ($row = mysql_fetch_assoc($res)) {
$torrents[$row["torrent"]]["comments"] = $row["c"];
// $res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent where torrent in ($idStr)");
$res = NexusDB::table("comments")
->selectRaw("torrent, COUNT(*) AS c")
->whereRaw("torrent in ($idStr)")
->groupBy(['torrent'])
->get();
foreach ($res as $row) {
$torrents[$row->torrent]["comments"] = $row["c"];
}
$seedersUpdates = $leechersUpdates = $commentsUpdates = [];
foreach ($torrentIdArr as $id) {
Expand All @@ -101,14 +111,14 @@ public function handle()
"update torrents set seeders = case id %s end, leechers = case id %s end, comments = case id %s end where id in (%s)",
implode(" ", $seedersUpdates), implode(" ", $leechersUpdates), implode(" ", $commentsUpdates), $idStr
);
$result = sql_query($sql);
$result = NexusDB::statement($sql);
if ($delIdRedisKey) {
NexusDB::cache_del($this->idRedisKey);
}
$costTime = time() - $beginTimestamp;
do_log(sprintf(
"$logPrefix, [DONE], update torrent count: %s, result: %s, cost time: %s seconds",
count($torrentIdArr), var_export($result, true), $costTime
"$logPrefix, [DONE], update torrent count: %s, result: %s, cost time: %s seconds, sql: %s",
count($torrentIdArr), var_export($result, true), $costTime, $sql
));
}

Expand Down
15 changes: 10 additions & 5 deletions app/Jobs/UpdateUserSeedingLeechingTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,25 @@ public function handle()
return;
}
//批量取,简单化
$res = sql_query("select userid, sum(seedtime) as seedtime_sum, sum(leechtime) as leechtime_sum from snatched group by userid where userid in ($idStr)");
// $res = sql_query("select userid, sum(seedtime) as seedtime_sum, sum(leechtime) as leechtime_sum from snatched group by userid where userid in ($idStr)");
$res = NexusDB::table("snatched")
->selectRaw("userid, sum(seedtime) as seedtime_sum, sum(leechtime) as leechtime_sum")
->whereRaw("userid in ($idStr)")
->groupBy("userid")
->get();
$seedtimeUpdates = $leechTimeUpdates = [];
$nowStr = now()->toDateTimeString();
$count = 0;
while ($row = mysql_fetch_assoc($res)) {
foreach ($res as $row) {
$count++;
$seedtimeUpdates = sprintf("when %d then %d", $row['userid'], $row['seedtime_sum'] ?? 0);
$leechTimeUpdates = sprintf("when %d then %d", $row['userid'], $row['leechtime_sum'] ?? 0);
$seedtimeUpdates = sprintf("when %d then %d", $row->userid, $row->seedtime_sum ?? 0);
$leechTimeUpdates = sprintf("when %d then %d", $row->userid, $row->leechtime_sum ?? 0);
}
$sql = sprintf(
"update users set seedtime = case id %s end, leechtime = case id %s end, seed_time_updated_at = '%s' where id in (%s)",
implode(" ", $seedtimeUpdates), implode(" ", $leechTimeUpdates), $nowStr, $idStr
);
$result = sql_query($sql);
$result = NexusDB::statement($sql);
if ($delIdRedisKey) {
NexusDB::cache_del($this->idRedisKey);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filament/widgets/stat-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
colspan="3"
@endif
>
<div class="px-4 py-3 filament-tables-text-column">{{$item['value']}}</div>
<div class="px-4 py-3 filament-tables-text-column"><span class="{{$item['class'] ?? ''}}">{{$item['value']}}</span></div>
</td>
@endforeach
</tr>
Expand Down

0 comments on commit 242857f

Please sign in to comment.