Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/php8' into php8
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Jul 22, 2024
2 parents 3a744eb + f320055 commit db1259a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
35 changes: 32 additions & 3 deletions app/Repositories/ExamRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Nexus\Database\NexusDB;

class ExamRepository extends BaseRepository
{
Expand Down Expand Up @@ -616,7 +617,7 @@ public function updateProgress($examUser, $user = null): ExamUser|bool
$attributes['index'] = $index['index'];
$attributes['created_at'] = $now;
$attributes['updated_at'] = $now;
$attributes['value'] = $this->getProgressValue($user, $index['index']);
$attributes['value'] = $this->getProgressValue($user, $index['index'], $examUser);
do_log("[GET_TOTAL_VALUE]: " . $attributes['value']);
$newVersionProgress = ExamProgress::query()
->where('exam_user_id', $examUser->id)
Expand Down Expand Up @@ -690,7 +691,7 @@ public function updateProgress($examUser, $user = null): ExamUser|bool
return $examUser;
}

private function getProgressValue(User $user, int $index)
private function getProgressValue(User $user, int $index, ExamUser $examUser)
{
if ($index == Exam::INDEX_UPLOADED) {
return $user->uploaded;
Expand All @@ -708,7 +709,7 @@ private function getProgressValue(User $user, int $index)
return $user->seed_points;
}
if ($index == Exam::INDEX_UPLOAD_TORRENT_COUNT) {
return Torrent::query()->where("owner", $user->id)->normal()->count();
return Torrent::query()->where("owner", $user->id)->where("added", ">=", $examUser->created_at)->normal()->count();
}
throw new \InvalidArgumentException("Invalid index: $index");
}
Expand Down Expand Up @@ -1302,4 +1303,32 @@ public function updateProgressBulk(): array
return $result;
}

public function fixIndexUploadTorrentCount()
{
$page = 1;
$size = 2000;
$examUserTable = (new ExamUser())->getTable();
$examProgressTable = (new ExamProgress())->getTable();
while (true) {
$offset = ($page - 1)*$size;
$list = NexusDB::table($examProgressTable)
->select("$examProgressTable.*, $examUserTable.created_at as exam_created_at")
->join($examUserTable, "$examProgressTable.exam_user_id", "=", "$examUserTable.id", "left")
->where("$examUserTable.status", ExamUser::STATUS_NORMAL)
->where("$examProgressTable.index", Exam::INDEX_UPLOAD_TORRENT_COUNT)
->limit($size)
->offset($offset)
->get()
;
if ($list->count() == 0) {
do_log("page: $page, offset: $offset, no more data...");
return;
}
foreach ($list as $item) {

}

}
}

}
8 changes: 8 additions & 0 deletions nexus/Install/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ public function runExtraQueries()
);
}

/**
* @since 1.8.13
*/
$settingName = "__has_fix_exam_index_UPLOAD_TORRENT_COUNT";
$hasFixExamIndexUploadTorrentCount = get_setting($settingName, false);
if (!$hasFixExamIndexUploadTorrentCount) {

}
}

public function runExtraMigrate()
Expand Down

0 comments on commit db1259a

Please sign in to comment.