fix getusertorrentlistajax hr

This commit is contained in:
xiaomlove
2022-03-10 21:45:23 +08:00
parent 40e36b715a
commit f0ced9cdf9
9 changed files with 113 additions and 39 deletions

View File

@@ -50,7 +50,7 @@ REDIS_PASSWORD=
REDIS_PORT=
REDIS_DB=
USE_CRON_TRIGGER_CLEANUP=false
USE_CRON_TRIGGER_CLEANUP=true
LOG_FILE=/tmp/nexus.log

View File

@@ -40,7 +40,7 @@ class AttendanceCleanup extends Command
{
$query = Attendance::query()->groupBy('uid')->selectRaw('uid, max(id) as max_id');
$page = 1;
$size = 1000;
$size = 10000;
while (true) {
$rows = $query->forPage($page, $size)->get();
$log = "sql: " . last_query() . ", count: " . $rows->count();

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands;
use App\Models\Attendance;
use App\Repositories\AttendanceRepository;
use Illuminate\Console\Command;
class AttendanceMigrate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'attendance:migrate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrate attendance from one time one record to one user one record.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$rep = new AttendanceRepository();
$result = $rep->migrateAttendance();
$log = sprintf('[%s], %s, result: %s, query: %s', REQUEST_ID, __METHOD__, var_export($result, true), last_query());
$this->info($log);
do_log($log);
return 0;
}
}

View File

@@ -63,7 +63,9 @@ class Test extends Command
*/
public function handle()
{
$rep = new AttendanceRepository();
$r = $rep->migrateAttendance();
dd($r);
}
}

View File

@@ -5,6 +5,7 @@ use App\Models\Attendance;
use App\Models\Setting;
use App\Models\User;
use Carbon\Carbon;
use Nexus\Database\NexusDB;
class AttendanceRepository extends BaseRepository
{
@@ -90,4 +91,51 @@ class AttendanceRepository extends BaseRepository
}
return $points;
}
public function migrateAttendance(): int
{
$page = 1;
$size = 10000;
$caseWhens = [];
$idArr = [];
while (true) {
$logPrefix = "[MIGRATE_ATTENDANCE], page: $page, size: $size";
$result = Attendance::query()
->groupBy(['uid'])
->selectRaw('uid, max(id) as id, count(*) as counts')
->forPage($page, $size)
->get();
do_log("$logPrefix, " . last_query() . ", count: " . $result->count());
if ($result->isEmpty()) {
do_log("$logPrefix, no more data...");
break;
}
foreach ($result as $row) {
//use case when instead.
$caseWhens[] = sprintf('when %s then %s', $row->id, $row->counts);
$idArr[] = $row->id;
// $update = [
// 'total_days' => $row->counts,
// ];
// $updateResult = $row->update($update);
do_log(sprintf(
"$logPrefix, update user: %s(ID: %s) => %s",
$row->uid, $row->id, $row->counts
));
}
$page++;
}
if (empty($caseWhens)) {
do_log("no data to update...");
return 0;
}
$caseWhenStr = sprintf('case id %s end', implode(' ', $caseWhens));
$result = Attendance::query()
->whereIn('id', $idArr)
->update(['total_days' => NexusDB::raw($caseWhenStr)]);
do_log("[MIGRATE_ATTENDANCE] DONE! $caseWhenStr, result: " . var_export($result, true));
return count($idArr);
}
}

View File

@@ -14,6 +14,7 @@ use App\Models\Tag;
use App\Models\Torrent;
use App\Models\TorrentTag;
use App\Models\User;
use App\Repositories\AttendanceRepository;
use App\Repositories\BonusRepository;
use App\Repositories\ExamRepository;
use App\Repositories\TagRepository;
@@ -140,7 +141,9 @@ class Update extends Install
}
if (!NexusDB::schema()->hasColumn('attendance', 'total_days')) {
$this->runMigrate('database/migrations/2021_06_13_215440_add_total_days_to_attendance_table.php');
$this->migrateAttendance();
$attendanceRep = new AttendanceRepository();
$count = $attendanceRep->migrateAttendance();
$this->doLog("[MIGRATE_ATTENDANCE] $count");
}
}
@@ -203,36 +206,6 @@ class Update extends Install
}
private function migrateAttendance()
{
$page = 1;
$size = 1000;
while (true) {
$logPrefix = "[MIGRATE_ATTENDANCE], page: $page, size: $size";
$result = Attendance::query()
->groupBy(['uid'])
->selectRaw('uid, max(id) as id, count(*) as counts')
->forPage($page, $size)
->get();
$this->doLog("$logPrefix, " . last_query() . ", count: " . $result->count());
if ($result->isEmpty()) {
$this->doLog("$logPrefix, no more data...");
break;
}
foreach ($result as $row) {
$update = [
'total_days' => $row->counts,
];
$updateResult = $row->update($update);
$this->doLog(sprintf(
"$logPrefix, update user: %s(ID: %s) => %s, result: %s",
$row->uid, $row->id, json_encode($update), var_export($updateResult, true)
));
}
$page++;
}
}
public function listVersions()
{

View File

@@ -104,6 +104,7 @@ if ($currentStep == 4) {
$tableRows = $settingTableRows['table_rows'];
$pass = $settingTableRows['pass'];
while ($isPost) {
set_time_limit(300);
try {
$install->createSymbolicLinks($symbolicLinks);
$install->runDatabaseSeeder();

View File

@@ -157,6 +157,7 @@ if ($currentStep == 4) {
$tableRows = $settingTableRows['table_rows'];
$pass = $settingTableRows['pass'];
while ($isPost) {
set_time_limit(300);
try {
// $update->updateDependencies();
$update->createSymbolicLinks($symbolicLinks);

View File

@@ -183,7 +183,7 @@ switch ($type)
{
case 'uploaded':
{
$res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, categories.name AS catname, categories.image, category, sp_state, size, hr, snatched.seedtime, snatched.uploaded FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id AND snatched.userid=$id " . (($CURUSER["id"] != $id)?((get_user_class() < $viewanonymous_class) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.added DESC") or sqlerr(__FILE__, __LINE__);
$res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, snatched.seedtime, snatched.uploaded FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id AND snatched.userid=$id " . (($CURUSER["id"] != $id)?((get_user_class() < $viewanonymous_class) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.added DESC") or sqlerr(__FILE__, __LINE__);
$count = mysql_num_rows($res);
if ($count > 0)
{
@@ -195,7 +195,7 @@ switch ($type)
// Current Seeding
case 'seeding':
{
$res = sql_query("SELECT torrent,added,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='yes' ORDER BY torrents.added DESC") or sqlerr();
$res = sql_query("SELECT torrent,added,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='yes' ORDER BY torrents.added DESC") or sqlerr();
$count = mysql_num_rows($res);
if ($count > 0){
list($torrentlist, $total_size) = maketable ( $res, 'seeding' );
@@ -206,7 +206,7 @@ switch ($type)
// Current Leeching
case 'leeching':
{
$res = sql_query("SELECT torrent,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='no' ORDER BY torrents.added DESC") or sqlerr();
$res = sql_query("SELECT torrent,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='no' ORDER BY torrents.added DESC") or sqlerr();
$count = mysql_num_rows($res);
if ($count > 0){
list($torrentlist, $total_size) = maketable ( $res, 'leeching' );
@@ -217,7 +217,7 @@ switch ($type)
// Completed torrents
case 'completed':
{
$res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, categories.name AS catname, categories.image, category, sp_state, size, hr,snatched.uploaded, snatched.seedtime, snatched.leechtime, snatched.completedat FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='yes' AND torrents.owner != $id AND userid=$id ORDER BY snatched.completedat DESC") or sqlerr();
$res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr,snatched.uploaded, snatched.seedtime, snatched.leechtime, snatched.completedat FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='yes' AND torrents.owner != $id AND userid=$id ORDER BY snatched.completedat DESC") or sqlerr();
$count = mysql_num_rows($res);
if ($count > 0)
{
@@ -229,7 +229,7 @@ switch ($type)
// Incomplete torrents
case 'incomplete':
{
$res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, categories.name AS catname, categories.image, category, sp_state, size, hr,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.startdat DESC") or sqlerr();
$res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.startdat DESC") or sqlerr();
$count = mysql_num_rows($res);
if ($count > 0)
{