Skip to content

Commit

Permalink
Merge pull request #107 from lanedirt/106-highscore-page-throws-error
Browse files Browse the repository at this point in the history
Fix highscore page, added tests
  • Loading branch information
lanedirt authored Apr 28, 2024
2 parents 0b67abc + 5cc5de4 commit 49e8abf
Show file tree
Hide file tree
Showing 15 changed files with 1,200 additions and 851 deletions.
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

0 comments on commit 49e8abf

Please sign in to comment.