Skip to content

Commit

Permalink
remove logs for faster queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Nov 27, 2023
1 parent fbfa601 commit 70ed7eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
25 changes: 11 additions & 14 deletions app/Http/Controllers/Admin/ServerIntelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,28 @@ public function overview(Request $request)
* Start: LAST 7 DAYS STATS
*/
// Unique Players Count
$uniquePlayers = MinecraftPlayerSession::select(['player_uuid'])
$uniquePlayersCount = MinecraftPlayer::select(['player_uuid'])
->when($selectedServers, function ($query, $selectedServers) {
$query->whereIn('server_id', $selectedServers);
})
->where('created_at', '>=', now()->subWeek())
->distinct()->get();
$uniquePlayersCount = $uniquePlayers->count();
->where('last_seen_at', '>=', now()->subWeek())
->distinct()->count('player_uuid');

// Old & New Players Count
$uniquePlayersSubquery = MinecraftPlayerSession::select(['player_uuid'])
$oldPlayersCount = MinecraftPlayer::select(['player_uuid'])
->when($selectedServers, function ($query, $selectedServers) {
$query->whereIn('server_id', $selectedServers);
})
->where('created_at', '>=', now()->subWeek())
->distinct()
->getQuery();
$oldPlayers = MinecraftPlayerSession::select(['player_uuid'])
->where('first_seen_at', '<', now()->subWeek())
->where('last_seen_at', '>=', now()->subWeek())
->distinct()->count('player_uuid');

$newPlayersCount = MinecraftPlayer::select(['player_uuid'])
->when($selectedServers, function ($query, $selectedServers) {
$query->whereIn('server_id', $selectedServers);
})
->where('created_at', '<', now()->subWeek())
->whereIn('player_uuid', $uniquePlayersSubquery)
->distinct()->get();
$oldPlayersCount = $oldPlayers->count();
$newPlayersCount = $uniquePlayers->whereNotIn('player_uuid', $oldPlayers->pluck('player_uuid'))->count();
->where('first_seen_at', '>=', now()->subWeek())
->distinct()->count('player_uuid');

// Peek Online Players
$peekOnlinePlayersCount = MinecraftServerLiveInfo::query()
Expand Down
9 changes: 6 additions & 3 deletions app/Jobs/CalculatePlayersRatingJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;

class CalculatePlayersRatingJob implements ShouldQueue
{
Expand All @@ -33,6 +34,8 @@ public function __construct()
*/
public function handle(PlayerSettings $playerSettings, PluginSettings $pluginSettings)
{
Log::info("[RatingJob] Starting calculating rating & ranks for all players");

$server = null;
if ($pluginSettings->enable_sync_player_ranks_from_server) {
$server = Server::where('id', $pluginSettings->sync_player_ranks_from_server_id)->first();
Expand Down Expand Up @@ -69,7 +72,7 @@ public function handle(PlayerSettings $playerSettings, PluginSettings $pluginSet
$pT->save();
}

\Log::info("[RatingJob] Finished calculating rating & ranks for all players");
Log::info("[RatingJob] Finished calculating rating & ranks for all players");
}

private function calculatePlayerRating($player, $minScore, $maxScore, PlayerSettings $playerSettings, array $serverIds): int|null
Expand All @@ -87,7 +90,7 @@ private function calculatePlayerRating($player, $minScore, $maxScore, PlayerSett
$playerRatingCalculator = new PlayerRatingCalculator();
$rating = $playerRatingCalculator->calculate($playerSettings->custom_rating_expression, $player, $serverIds);
} catch (\Exception $e) {
\Log::critical($e);
Log::critical($e);
$rating = null;
}
} else {
Expand Down Expand Up @@ -128,7 +131,7 @@ private function calculatePlayerRankIdFromServerWebQuery($serverHost, $serverPor
->orderByDesc('weight')->first()?->id;
}
} catch(\Exception $e) {
\Log::critical($e);
Log::critical($e);
}

return $rankId;
Expand Down
5 changes: 1 addition & 4 deletions app/Jobs/CalculatePlayersScoreJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct()
*/
public function handle(PlayerSettings $playerSettings)
{
Log::info('[ScoreJob] Starting calculating scores for all players');
$playerSettings->refresh();

// id list of all servers.
Expand All @@ -48,8 +49,6 @@ public function handle(PlayerSettings $playerSettings)
->selectRaw('sum(vault_balance) as vault_balance')
->first();
if ($mcPlayerDataFromServer->updated_at < $player->updated_at && ! $shouldForceRunForAllPlayers) {
Log::info('[ScoreJob] Skipping player: '.$player->uuid.' as it is already up to date');

continue;
}

Expand All @@ -59,8 +58,6 @@ public function handle(PlayerSettings $playerSettings)
'total_score' => $score,
'total_money' => $mcPlayerDataFromServer->vault_balance ?? 0,
]);

Log::info('[ScoreJob] Calculated score for player: '.$player->uuid.' as '.$score);
}

Log::info('[ScoreJob] Finished calculating scores for all players');
Expand Down

0 comments on commit 70ed7eb

Please sign in to comment.