mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
claim bulk
This commit is contained in:
@@ -95,7 +95,8 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$logFile = getLogFile("seed-points");
|
||||
dd($logFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,9 @@ class CalculateUserSeedBonus implements ShouldQueue
|
||||
$autoclean_interval_one = Setting::get('main.autoclean_interval_one');
|
||||
$sql = sprintf("select %s from users where id in (%s)", implode(',', User::$commonFields), implode(',', array_column($results, 'userid')));
|
||||
$results = NexusDB::select($sql);
|
||||
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results));
|
||||
$logFile = getLogFile("seed-bonus-points");
|
||||
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results) . ", logFile: $logFile");
|
||||
$fd = fopen($logFile, 'a');
|
||||
foreach ($results as $userInfo)
|
||||
{
|
||||
$uid = $userInfo['id'];
|
||||
@@ -107,6 +109,17 @@ class CalculateUserSeedBonus implements ShouldQueue
|
||||
$sql = "update users set seed_points = ifnull(seed_points, 0) + $seed_points, seedbonus = seedbonus + $all_bonus, seed_points_updated_at = '$updatedAt' where id = $uid limit 1";
|
||||
do_log("$bonusLog, query: $sql");
|
||||
NexusDB::statement($sql);
|
||||
if ($fd) {
|
||||
$log = sprintf(
|
||||
'%s|%s|%s|%s|%s|%s|%s|%s',
|
||||
date('Y-m-d H:i:s'), $uid,
|
||||
$userInfo['seed_points'], number_format($seed_points, 1, '.', ''), number_format($userInfo['seed_points'] + $seed_points, 1, '.', ''),
|
||||
$userInfo['seedbonus'], number_format($all_bonus, 1, '.', ''), number_format($userInfo['seedbonus'] + $all_bonus, 1, '.', '')
|
||||
);
|
||||
fwrite($fd, $log . PHP_EOL);
|
||||
} else {
|
||||
do_log("logFile: $logFile is not writeable!", 'error');
|
||||
}
|
||||
}
|
||||
$costTime = time() - $beginTimestamp;
|
||||
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Exceptions\InsufficientPermissionException;
|
||||
use App\Models\Claim;
|
||||
use App\Models\Message;
|
||||
use App\Models\Peer;
|
||||
@@ -59,7 +60,7 @@ class ClaimRepository extends BaseRepository
|
||||
if ($torrent->added->addDays($claimTorrentTTL)->gte(Carbon::now())) {
|
||||
throw new \RuntimeException(nexus_trans("torrent.can_no_be_claimed_yet"));
|
||||
}
|
||||
if (!apply_filter('user_has_role_work_seeding', false, $uid)) {
|
||||
if (!has_role_work_seeding($uid)) {
|
||||
$max = Claim::getConfigTorrentUpLimit();
|
||||
$count = Claim::query()->where('uid', $uid)->count();
|
||||
if ($count >= $max) {
|
||||
@@ -162,7 +163,7 @@ class ClaimRepository extends BaseRepository
|
||||
|
||||
public function settleUser($uid, $force = false, $test = false): bool
|
||||
{
|
||||
$hasRoleWorkSeeding = apply_filter('user_has_role_work_seeding', false, $uid);
|
||||
$hasRoleWorkSeeding = has_role_work_seeding($uid);
|
||||
if ($hasRoleWorkSeeding) {
|
||||
do_log("uid: $uid, filter: user_has_role_work_seeding => true, skip");
|
||||
return false;
|
||||
@@ -346,21 +347,24 @@ class ClaimRepository extends BaseRepository
|
||||
|
||||
public function claimAllSeeding(int $uid)
|
||||
{
|
||||
if (!has_role_work_seeding($uid)) {
|
||||
throw new InsufficientPermissionException();
|
||||
}
|
||||
$page = 1;
|
||||
$size = 1000;
|
||||
$total = 0;
|
||||
while (true) {
|
||||
$peers = Peer::query()
|
||||
->where('uid', $uid)
|
||||
->where('userid', $uid)
|
||||
->where('seeder', 'yes')
|
||||
->where('to_go', 0)
|
||||
->groupBy('torrentid')
|
||||
->groupBy('torrent')
|
||||
->forPage($page, $size)
|
||||
->get(['torrentid']);
|
||||
->get(['torrent']);
|
||||
if ($peers->isEmpty()) {
|
||||
break;
|
||||
}
|
||||
$torrentIdArr = $peers->pluck('torrentid')->toArray();
|
||||
$torrentIdArr = $peers->pluck('torrent')->toArray();
|
||||
$snatches = Snatch::query()
|
||||
->whereIn('torrentid', $torrentIdArr)
|
||||
->where('userid', $uid)
|
||||
@@ -369,7 +373,7 @@ class ClaimRepository extends BaseRepository
|
||||
if ($snatches->isNotEmpty()) {
|
||||
$values = [];
|
||||
$nowStr = now()->toDateTimeString();
|
||||
$sql = "insert into claims (uid, torrent_id, snatched_id, seed_time_begin, uploaded_begin, created_at, uploaded_at)";
|
||||
$sql = "insert into claims (uid, torrent_id, snatched_id, seed_time_begin, uploaded_begin, created_at, updated_at)";
|
||||
foreach ($snatches as $snatch) {
|
||||
$values[] = sprintf(
|
||||
"(%s, %s, %s, %s, %s, '%s', '%s')",
|
||||
|
||||
Reference in New Issue
Block a user