Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix highscore page, added tests #107

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Http/Controllers/HighscoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class HighscoreController extends OGameController
*/
public function index(Request $request, PlayerService $player) : View
{
$this->setBodyId('highscore');

return view('ingame.highscore.index')->with([
'initialContent' => $this->ajax($request, $player),
]);
Expand Down
13 changes: 11 additions & 2 deletions app/Services/HighscoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function getPlayerScoreMilitary(PlayerService $player): int
*
* @param PlayerService $player
* @return int
* @throws Exception
*/
public function getPlayerScoreEconomy(PlayerService $player): int
{
Expand All @@ -126,7 +127,9 @@ public function getPlayerScoreEconomy(PlayerService $player): int
public function getHighscorePlayers(int $offset_start = 0, int $return_amount = 100): array
{
// Get all players
$players = User::all();
// TODO: when cached highscore results are available, remove this max 110 players limit.
// This limit is added to prevent loading all players in memory at once which causes timeout issues.
$players = User::take(110)->get();
$highscore = [];
$count = 0;
foreach ($players as $player) {
Expand Down Expand Up @@ -217,6 +220,12 @@ public function getHighscorePlayerRank(PlayerService $player): int
*/
public function getHighscorePlayerAmount() : int
{
return User::count();
// TODO: return actual player count again when caching is implemented.
$actualUserCount = User::count();
if ($actualUserCount > 110) {
return 110;
}

return $actualUserCount;
}
}
Loading
Loading