From a4058e0692992337a7f736e6511d2b55308ad7f5 Mon Sep 17 00:00:00 2001 From: Jamiras Date: Thu, 26 Oct 2023 20:35:02 -0600 Subject: [PATCH] remove aggregate queries config check --- app/Helpers/database/player-game.php | 54 +++++++++++++--------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/app/Helpers/database/player-game.php b/app/Helpers/database/player-game.php index 60f866020d..9080eef86a 100644 --- a/app/Helpers/database/player-game.php +++ b/app/Helpers/database/player-game.php @@ -702,44 +702,40 @@ function getTotalUniquePlayers( function getGameRecentPlayers(int $gameID, int $maximum_results = 10): array { $retval = []; - $filter = ''; - if (config('feature.aggregate_queries')) { - $sessions = PlayerSession::where('game_id', $gameID) - ->join('UserAccounts', 'UserAccounts.ID', '=', 'user_id') - ->where('UserAccounts.Permissions', '>=', Permissions::Unregistered) - ->whereNotNull('rich_presence') - ->orderBy('rich_presence_updated_at', 'DESC') - ->groupBy('user_id') - ->select(['user_id', 'User', 'rich_presence', DB::raw('MAX(rich_presence_updated_at) AS rich_presence_updated_at')]); - - if ($maximum_results) { - $sessions = $sessions->limit($maximum_results); - } + $sessions = PlayerSession::where('game_id', $gameID) + ->join('UserAccounts', 'UserAccounts.ID', '=', 'user_id') + ->where('UserAccounts.Permissions', '>=', Permissions::Unregistered) + ->whereNotNull('rich_presence') + ->orderBy('rich_presence_updated_at', 'DESC') + ->groupBy('user_id') + ->select(['user_id', 'User', 'rich_presence', DB::raw('MAX(rich_presence_updated_at) AS rich_presence_updated_at')]); - foreach ($sessions->get() as $session) { - $retval[] = [ - 'UserID' => $session->user_id, - 'User' => $session->User, - 'Date' => $session->rich_presence_updated_at->__toString(), - 'Activity' => $session->rich_presence, - ]; - } + if ($maximum_results) { + $sessions = $sessions->limit($maximum_results); + } - if ($maximum_results) { - $maximum_results -= count($retval); - if ($maximum_results == 0) { - return $retval; - } - } + foreach ($sessions->get() as $session) { + $retval[] = [ + 'UserID' => $session->user_id, + 'User' => $session->User, + 'Date' => $session->rich_presence_updated_at->__toString(), + 'Activity' => $session->rich_presence, + ]; + } - $filter = 'AND ua.ID NOT IN (' . implode(',', array_column($retval, 'UserID')) . ')'; + if ($maximum_results) { + $maximum_results -= count($retval); + if ($maximum_results == 0) { + return $retval; + } } $query = "SELECT ua.ID as UserID, ua.User, ua.RichPresenceMsgDate AS Date, ua.RichPresenceMsg AS Activity FROM UserAccounts AS ua WHERE ua.LastGameID = $gameID AND ua.Permissions >= " . Permissions::Unregistered . " - AND ua.RichPresenceMsgDate > TIMESTAMPADD(MONTH, -6, NOW()) $filter + AND ua.RichPresenceMsgDate > TIMESTAMPADD(MONTH, -6, NOW()) + AND ua.ID NOT IN (" . implode(',', array_column($retval, 'UserID')) . ") ORDER BY ua.RichPresenceMsgDate DESC"; if ($maximum_results > 0) {