improve claim all seeding

This commit is contained in:
xiaomlove
2023-04-09 16:33:36 +08:00
parent 33b16ed7ac
commit b8f1690124
10 changed files with 10 additions and 58 deletions

View File

@@ -345,49 +345,5 @@ 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('userid', $uid)
->where('seeder', 'yes')
->where('to_go', 0)
->groupBy('torrent')
->forPage($page, $size)
->get(['torrent']);
if ($peers->isEmpty()) {
break;
}
$torrentIdArr = $peers->pluck('torrent')->toArray();
$snatches = Snatch::query()
->whereIn('torrentid', $torrentIdArr)
->where('userid', $uid)
->groupBy('torrentid')
->get(['id', 'torrentid', 'seedtime', 'uploaded']);
if ($snatches->isNotEmpty()) {
$values = [];
$nowStr = now()->toDateTimeString();
$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')",
$uid, $snatch->torrentid, $snatch->id, $snatch->seedtime, $snatch->uploaded, $nowStr, $nowStr
);
}
$sql .= sprintf(" values %s on duplicate key update updated_at = '%s'", implode(', ', $values), $nowStr);
NexusDB::statement($sql);
}
$count = $snatches->count();
$total += $count;
do_log("page: $page, insert rows count: " . $count);
$page++;
}
return $total;
}
}

View File

@@ -1178,6 +1178,8 @@ function executeCommand($command, $format = 'string', $artisan = false, $excepti
function has_role_work_seeding($uid)
{
return apply_filter('user_has_role_work_seeding', false, $uid);
$result = apply_filter('user_has_role_work_seeding', false, $uid);
do_log("uid: $uid, result: $result");
return $result;
}

View File

@@ -123,7 +123,7 @@ $lang_details = array
'text_hide_list' => "[隐藏列表]",
'row_action' => "行为",
'text_download_torrent' => "下载种子",
'text_download_paid_torrent' => "下载种子(扣除魔力:%s)",
'text_download_paid_torrent' => "下载种子(汇报时将扣除魔力:%s)",
'text_download_bought_torrent' => "下载种子(已购买)",
'title_download_torrent' => "下载种子",
'text_ask_for_reseed' => "请求续种",

View File

@@ -123,7 +123,7 @@ $lang_details = array
'text_hide_list' => "[隱藏清單]",
'row_action' => "行為",
'text_download_torrent' => "下載種子",
'text_download_paid_torrent' => "下載種子(扣除魔力:%s)",
'text_download_paid_torrent' => "下載種子(匯報時將扣除魔力:%s)",
'text_download_bought_torrent' => "下載種子(已購買)",
'title_download_torrent' => "下載種子",
'text_ask_for_reseed' => "要求續種",

View File

@@ -122,7 +122,7 @@ $lang_details = array
'text_hide_list' => "[Hide list]",
'row_action' => "Action",
'text_download_torrent' => "Download torrent",
'text_download_paid_torrent' => "Download torrent(deduct bonus: %s)",
'text_download_paid_torrent' => "Download torrent(announce will deduct bonus: %s)",
'text_download_bought_torrent' => "Download torrent(bought)",
'title_download_torrent' => "Download torrent",
'text_ask_for_reseed' => "Ask for a reseed",

View File

@@ -353,11 +353,8 @@ if (isset($total_size) && $total_size){
$hasData = true;
}
if ($hasData) {
$claimAllBtn = '';
if ($id == $CURUSER['id'] && has_role_work_seeding($CURUSER['id'])) {
$claimAllBtn = sprintf('<input type="button" value="%s" id="claim-all-seeding">', nexus_trans('claim.claim_all_seeding_btn'));
}
$header = sprintf('<div style="display: flex;justify-content: space-between"><div>%s</div><div>%s</div></div>', $summary, $claimAllBtn);
$btnArr = apply_filter("user_seeding_top_btn", [], $CURUSER['id']);
$header = sprintf('<div style="display: flex;justify-content: space-between"><div>%s</div><div>%s</div></div>', $summary, implode("", $btnArr));
echo '<br/>' . $header . $table;
} else {
echo $lang_getusertorrentlistajax['text_no_record'];

View File

@@ -633,7 +633,7 @@ if ($userInfo->id == $CURUSER['id'] && has_role_work_seeding($userInfo->id)) {
$claimJs = <<<JS
jQuery("body").on("click", "#claim-all-seeding", function (e) {
layer.confirm("$claimAllSeedingConfirmation", {}, function () {
jQuery.post('ajax.php', {"action": "claimAllSeeding"}, function (response) {
jQuery.post('/plugin/claim_all_seeding', {"action": "claimAllSeeding"}, function (response) {
if (response.ret == 0) {
window.location.reload()
} else {

View File

@@ -34,6 +34,5 @@ return [
'fields' => [
'torrent_id' => 'Torrent ID',
],
'claim_all_seeding_btn' => 'One click to claim',
'claim_all_seeding_confirmation' => 'Are you sure you want to claim all the torrents that are currently being seeding?' ,
];

View File

@@ -36,7 +36,6 @@ return [
'torrent_id' => '种子 ID',
],
'claim_all_seeding_btn' => '一键认领',
'claim_all_seeding_confirmation' => '确定要认领当前全部做种中的种子吗?',
];

View File

@@ -33,6 +33,5 @@ return [
'fields' => [
'torrent_id' => '種子 ID',
],
'claim_all_seeding_btn' => '一鍵認領',
'claim_all_seeding_confirmation' => '確定要認領當前全部做種中的種子嗎?',
];