mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
improve index latest page query
This commit is contained in:
@@ -98,9 +98,11 @@ class AttendanceRepository extends BaseRepository
|
|||||||
$size = 10000;
|
$size = 10000;
|
||||||
$caseWhens = [];
|
$caseWhens = [];
|
||||||
$idArr = [];
|
$idArr = [];
|
||||||
|
$table = 'attendance';
|
||||||
while (true) {
|
while (true) {
|
||||||
$logPrefix = "[MIGRATE_ATTENDANCE], page: $page, size: $size";
|
$logPrefix = "[MIGRATE_ATTENDANCE], page: $page, size: $size";
|
||||||
$result = Attendance::query()
|
//as soon as possible, don't use eloquent
|
||||||
|
$result = NexusDB::table($table)
|
||||||
->groupBy(['uid'])
|
->groupBy(['uid'])
|
||||||
->selectRaw('uid, max(id) as id, count(*) as counts')
|
->selectRaw('uid, max(id) as id, count(*) as counts')
|
||||||
->forPage($page, $size)
|
->forPage($page, $size)
|
||||||
@@ -111,13 +113,8 @@ class AttendanceRepository extends BaseRepository
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
//use case when instead.
|
|
||||||
$caseWhens[] = sprintf('when %s then %s', $row->id, $row->counts);
|
$caseWhens[] = sprintf('when %s then %s', $row->id, $row->counts);
|
||||||
$idArr[] = $row->id;
|
$idArr[] = $row->id;
|
||||||
// $update = [
|
|
||||||
// 'total_days' => $row->counts,
|
|
||||||
// ];
|
|
||||||
// $updateResult = $row->update($update);
|
|
||||||
do_log(sprintf(
|
do_log(sprintf(
|
||||||
"$logPrefix, update user: %s(ID: %s) => %s",
|
"$logPrefix, update user: %s(ID: %s) => %s",
|
||||||
$row->uid, $row->id, $row->counts
|
$row->uid, $row->id, $row->counts
|
||||||
@@ -130,7 +127,7 @@ class AttendanceRepository extends BaseRepository
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$caseWhenStr = sprintf('case id %s end', implode(' ', $caseWhens));
|
$caseWhenStr = sprintf('case id %s end', implode(' ', $caseWhens));
|
||||||
$result = Attendance::query()
|
$result = NexusDB::table($table)
|
||||||
->whereIn('id', $idArr)
|
->whereIn('id', $idArr)
|
||||||
->update(['total_days' => NexusDB::raw($caseWhenStr)]);
|
->update(['total_days' => NexusDB::raw($caseWhenStr)]);
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ if ($showlastxforumposts_main == "yes" && $CURUSER)
|
|||||||
// ------------- start: latest torrents ------------------//
|
// ------------- start: latest torrents ------------------//
|
||||||
|
|
||||||
if ($showlastxtorrents_main == "yes") {
|
if ($showlastxtorrents_main == "yes") {
|
||||||
$result = sql_query("SELECT * FROM torrents where visible='yes' ORDER BY added DESC LIMIT 5") or sqlerr(__FILE__, __LINE__);
|
$result = sql_query("SELECT id,name,leechers,seeders FROM torrents where visible='yes' ORDER BY id DESC LIMIT 5") or sqlerr(__FILE__, __LINE__);
|
||||||
if(mysql_num_rows($result) != 0 )
|
if(mysql_num_rows($result) != 0 )
|
||||||
{
|
{
|
||||||
print ("<h2>".$lang_index['text_last_five_torrent']."</h2>");
|
print ("<h2>".$lang_index['text_last_five_torrent']."</h2>");
|
||||||
|
|||||||
Reference in New Issue
Block a user