mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
fix getusertorrentlistajax hr
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
49
app/Console/Commands/AttendanceMigrate.php
Normal file
49
app/Console/Commands/AttendanceMigrate.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,9 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$rep = new AttendanceRepository();
|
||||
$r = $rep->migrateAttendance();
|
||||
dd($r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user