From 3c6d1a4787fa57d475c378f607f79a80b6c28dc9 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 14 Jun 2021 12:49:16 +0800 Subject: [PATCH] add promotion and announce_waint log --- app/Repositories/ExamRepository.php | 37 +++++++++++++++++++++-- classes/class_attendance.php | 10 +++--- include/cleanup.php | 9 +++++- include/functions.php | 47 +++++++++++++++++++++-------- public/announce.php | 18 +++++++---- 5 files changed, 94 insertions(+), 27 deletions(-) diff --git a/app/Repositories/ExamRepository.php b/app/Repositories/ExamRepository.php index f913af87..d94ebc28 100644 --- a/app/Repositories/ExamRepository.php +++ b/app/Repositories/ExamRepository.php @@ -444,6 +444,10 @@ class ExamRepository extends BaseRepository do_log("examUser: {$examUser->id} status not normal, won't update progress."); return false; } + if ($examUser->is_done == ExamUser::IS_DONE_YES) { + do_log("examUser: {$examUser->id} is done, won't update progress."); + return false; + } $exam = $examUser->exam; if (!$user instanceof User) { $user = $examUser->user()->select(['id', 'uploaded', 'downloaded', 'seedtime', 'leechtime', 'seedbonus'])->first(); @@ -799,7 +803,7 @@ class ExamRepository extends BaseRepository return $result; } - public function cronjobCheckout($ignoreTimeRange = false) + public function cronjobCheckout($ignoreTimeRange = false): int { $now = Carbon::now()->toDateTimeString(); $examUserTable = (new ExamUser())->getTable(); @@ -906,7 +910,34 @@ class ExamRepository extends BaseRepository return $result; } - - + public function updateProgressBulk(): array + { + $query = ExamUser::query() + ->where('status', ExamUser::STATUS_NORMAL) + ->where('is_done', ExamUser::IS_DONE_NO); + $page = 1; + $size = 1000; + $total = $success = 0; + while (true) { + $logPrefix = "[UPDATE_EXAM_PROGRESS], page: $page, size: $size"; + $rows = $query->forPage($page, $size)->get(); + $count = $rows->count(); + $total += $count; + do_log("$logPrefix, " . last_query() . ", count: $count"); + if ($rows->isEmpty()) { + do_log("$logPrefix, no more data..."); + break; + } + foreach ($rows as $row) { + $result = $this->updateProgress($row); + do_log("$logPrefix, examUser: " . $row->toJson() . ", result type: " . gettype($result)); + if ($result != false) { + $success += 1; + } + } + $page++; + } + return compact('total', 'success'); + } } diff --git a/classes/class_attendance.php b/classes/class_attendance.php index bbabecf2..0d983895 100644 --- a/classes/class_attendance.php +++ b/classes/class_attendance.php @@ -24,15 +24,15 @@ class Attendance { do_log(json_encode(func_get_args())); if($this->check(true)) return false; - $res = sql_query(sprintf('SELECT DATEDIFF(%s, `added`) AS diff, `days`, `total_days` FROM `attendance` WHERE `uid` = %u ORDER BY `id` DESC LIMIT 1', sqlesc($this->curdate), $this->userid)) or sqlerr(__FILE__,__LINE__); + $res = sql_query(sprintf('SELECT id, DATEDIFF(%s, `added`) AS diff, `days`, `total_days` FROM `attendance` WHERE `uid` = %u ORDER BY `id` DESC LIMIT 1', sqlesc($this->curdate), $this->userid)) or sqlerr(__FILE__,__LINE__); $doUpdate = mysql_num_rows($res); if ($doUpdate) { $row = mysql_fetch_row($res); do_log("uid: {$this->userid}, row: " . json_encode($row)); } else { - $row = [0, 0, 0]; + $row = [0, 0, 0, 0]; } - list($datediff, $days, $totalDays) = $row; + list($id, $datediff, $days, $totalDays) = $row; $points = min($initial + $step * $totalDays, $maximum); $cdays = $datediff == 1 ? ++$days : 1; if($cdays > 1){ @@ -47,8 +47,8 @@ class Attendance // sql_query(sprintf('INSERT INTO `attendance` (`uid`,`added`,`points`,`days`) VALUES (%u, %s, %u, %u)', $this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays)) or sqlerr(__FILE__, __LINE__); if ($doUpdate) { $sql = sprintf( - 'UPDATE `attendance` set added = %s, points = %s, days = %s, total_days= %s where uid = %s order by id desc limit 1', - sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $this->userid + 'UPDATE `attendance` set added = %s, points = %s, days = %s, total_days= %s where id = %s limit 1', + sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $id ); } else { $sql = sprintf( diff --git a/include/cleanup.php b/include/cleanup.php index 8d2d471e..4dcfe562 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -223,7 +223,6 @@ function delete_user(\Illuminate\Database\Eloquent\Builder $query, $reasonKey) return $uidArr; } - function docleanup($forceAll = 0, $printProgress = false) { //require_once(get_langfile_path("cleanup.php",true)); global $lang_cleanup_target; @@ -294,6 +293,14 @@ function docleanup($forceAll = 0, $printProgress = false) { printProgress($log); } + $examRep = new \App\Repositories\ExamRepository(); + $updateExamProgressResult = $examRep->updateProgressBulk(); + $log = 'update exam progress'; + do_log($log . ", result: " . json_encode($updateExamProgressResult)); + if ($printProgress) { + printProgress($log); + } + //Priority Class 2: cleanup every 30 mins $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime2'"); $row = mysql_fetch_array($res); diff --git a/include/functions.php b/include/functions.php index 60efbff5..3e6bbb54 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3956,6 +3956,8 @@ function get_torrent_promotion_append($promotion = 1,$forcemode = "",$showtimele $sp_torrent = ""; $onmouseover = ""; + $log = "[GET_PROMOTION], promotion: $promotion, forcemode: $forcemode, showtimeleft: $showtimeleft, added: $added, promotionTimeType: $promotionTimeType, promotionUntil: $promotionUntil"; + $log .= ", get_global_sp_state() == " . get_global_sp_state(); if (get_global_sp_state() == 1) { switch ($promotion){ case 2: @@ -4057,39 +4059,60 @@ function get_torrent_promotion_append($promotion = 1,$forcemode = "",$showtimele } } if (($CURUSER['appendpromotion'] == 'word' && $forcemode == "" ) || $forcemode == 'word'){ + $log .= ", user appendpromotion = word"; if(($promotion==2 && get_global_sp_state() == 1) || get_global_sp_state() == 2){ + $log .= ", promotion or global_sp_state = 2"; $sp_torrent = " [".$lang_functions['text_free']."]"; } elseif(($promotion==3 && get_global_sp_state() == 1) || get_global_sp_state() == 3){ + $log .= ", promotion or global_sp_state = 3"; $sp_torrent = " [".$lang_functions['text_two_times_up']."]"; } elseif(($promotion==4 && get_global_sp_state() == 1) || get_global_sp_state() == 4){ + $log .= ", promotion or global_sp_state = 4"; $sp_torrent = " [".$lang_functions['text_free_two_times_up']."]"; } elseif(($promotion==5 && get_global_sp_state() == 1) || get_global_sp_state() == 5){ + $log .= ", promotion or global_sp_state = 5"; $sp_torrent = " [".$lang_functions['text_half_down']."]"; } elseif(($promotion==6 && get_global_sp_state() == 1) || get_global_sp_state() == 6){ + $log .= ", promotion or global_sp_state = 6"; $sp_torrent = " [".$lang_functions['text_half_down_two_up']."]"; } elseif(($promotion==7 && get_global_sp_state() == 1) || get_global_sp_state() == 7){ + $log .= ", promotion or global_sp_state = 7"; $sp_torrent = " [".$lang_functions['text_thirty_percent_down']."]"; } } elseif (($CURUSER['appendpromotion'] == 'icon' && $forcemode == "") || $forcemode == 'icon'){ - if(($promotion==2 && get_global_sp_state() == 1) || get_global_sp_state() == 2) - $sp_torrent = " \"Free\""; - elseif(($promotion==3 && get_global_sp_state() == 1) || get_global_sp_state() == 3) - $sp_torrent = " \"2X\""; - elseif(($promotion==4 && get_global_sp_state() == 1) || get_global_sp_state() == 4) - $sp_torrent = " \"2X"; - elseif(($promotion==5 && get_global_sp_state() == 1) || get_global_sp_state() == 5) - $sp_torrent = " \"50%\""; - elseif(($promotion==6 && get_global_sp_state() == 1) || get_global_sp_state() == 6) - $sp_torrent = " \"2X"; - elseif(($promotion==7 && get_global_sp_state() == 1) || get_global_sp_state() == 7) - $sp_torrent = " \"30%\""; + $log .= ", user appendpromotion = icon"; + if(($promotion==2 && get_global_sp_state() == 1) || get_global_sp_state() == 2) { + $log .= ", promotion or global_sp_state = 2"; + $sp_torrent = " \"Free\""; + } + elseif(($promotion==3 && get_global_sp_state() == 1) || get_global_sp_state() == 3) { + $log .= ", promotion or global_sp_state = 3"; + $sp_torrent = " \"2X\""; + } + elseif(($promotion==4 && get_global_sp_state() == 1) || get_global_sp_state() == 4) { + $log .= ", promotion or global_sp_state = 4"; + $sp_torrent = " \"2X"; + } + elseif(($promotion==5 && get_global_sp_state() == 1) || get_global_sp_state() == 5) { + $log .= ", promotion or global_sp_state = 5"; + $sp_torrent = " \"50%\""; + } + elseif(($promotion==6 && get_global_sp_state() == 1) || get_global_sp_state() == 6) { + $log .= ", promotion or global_sp_state = 6"; + $sp_torrent = " \"2X"; + } + elseif(($promotion==7 && get_global_sp_state() == 1) || get_global_sp_state() == 7) { + $log .= ", promotion or global_sp_state = 7"; + $sp_torrent = " \"30%\""; + } } + do_log("$log, sp_torrent: $sp_torrent"); return $sp_torrent; } diff --git a/public/announce.php b/public/announce.php index 121c2f1d..3630bcfa 100644 --- a/public/announce.php +++ b/public/announce.php @@ -79,15 +79,15 @@ $seeder = ($left == 0) ? "yes" : "no"; // check passkey if (!$az = $Cache->get_value('user_passkey_'.$passkey.'_content')){ - $res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror,passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1"); - $az = $currentUser = mysql_fetch_array($res); - do_log("[check passkey], currentUser: " . nexus_json_encode($currentUser), 'error'); + $res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror, passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1"); + $az = mysql_fetch_array($res); + do_log("[check passkey], currentUser: " . nexus_json_encode($az), 'error'); $Cache->cache_value('user_passkey_'.$passkey.'_content', $az, 950); } if (!$az) err("Invalid passkey! Re-download the .torrent from $BASEURL"); $userid = intval($az['id'] ?? 0); unset($GLOBALS['CURUSER']); -$CURUSER = $GLOBALS["CURUSER"] = $currentUser; +$CURUSER = $GLOBALS["CURUSER"] = $az; //3. CHECK IF CLIENT IS ALLOWED $clicheck_res = check_client($peer_id,$agent,$client_familyid); @@ -206,8 +206,14 @@ if (!isset($self)) } // min announce time -if(isset($self) && $self['prevts'] > (TIMENOW - $announce_wait)) - err('There is a minimum announce time of ' . $announce_wait . ' seconds'); +if(isset($self) && $self['prevts'] > (TIMENOW - $announce_wait)) { + do_log(sprintf( + 'timezone: %s, self prevts(%s, %s) > now(%s, %s) - announce_wait(%s)', + ini_get('date.timezone'), $self['prevts'], date('Y-m-d H:i:s', $self['prevts']), TIMENOW, date('Y-m-d H:i:s', TIMENOW), $announce_wait + )); + err('There is a minimum announce time of ' . $announce_wait . ' seconds'); +} + // current peer_id, or you could say session with tracker not found in table peers if (!isset($self))