Skip to content

Commit 6b045c3

Browse files
add debug logs in PodiumController (#417)
* add debug logs in PodiumController * filter out observers from players_in queue count * Add back missing cache to player stat views, tweak cache to 10 mins (#418) --------- Co-authored-by: Grant Bartlett <[email protected]>
1 parent 552d50c commit 6b045c3

File tree

4 files changed

+60
-50
lines changed

4 files changed

+60
-50
lines changed

cncnet-api/app/Http/Controllers/Admin/PodiumController.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ public function getPodiumForm()
2121
->where('private', 0)
2222
->pluck('name', 'id')
2323
->toArray();
24+
Log::debug('Entering getPodiumForm in PodiumController');
2425
$fromDate = Carbon::now()->subWeek()->endOfWeek()->subDays(2)->setTime(20, 0, 0);
2526
$toDate = Carbon::now()->subWeek()->endOfWeek()->setTime(22, 0, 0);
2627
return view('admin.podium', compact('ladders', 'fromDate', 'toDate'));
2728
}
2829

29-
public function computePodium(ComputePodiumRequest $request) {
30-
31-
if (RateLimiter::tooManyAttempts($this->getRateLimiterKey(), 1)) {
30+
public function computePodium(ComputePodiumRequest $request)
31+
{
32+
Log::debug('Entering computePodium in PodiumController', ['user_id' => auth()->id(), 'request' => $request->all()]);
33+
if (RateLimiter::tooManyAttempts($this->getRateLimiterKey(), 1))
34+
{
3235
$seconds = RateLimiter::availableIn($this->getRateLimiterKey());
33-
$message = 'Don\'t submit this form this too often... You may try again in '.$seconds.' seconds.';
36+
$message = 'Don\'t submit this form this too often... You may try again in ' . $seconds . ' seconds.';
3437
return view('admin.podium.result-too-many-attempts', compact('message'));
3538
}
3639

@@ -41,7 +44,8 @@ public function computePodium(ComputePodiumRequest $request) {
4144
$from = Carbon::createFromFormat('Y-m-d H:i', $inputs['date_from'] . ' ' . $inputs['time_from']);
4245
$to = Carbon::createFromFormat('Y-m-d H:i', $inputs['date_to'] . ' ' . $inputs['time_to']);
4346

44-
if ($from->diffInDays($to, true) > 31) {
47+
if ($from->diffInDays($to, true) > 31)
48+
{
4549
return redirect()->back()->withErrors([
4650
'period' => 'Please select a period of 1 month or less.'
4751
]);
@@ -69,7 +73,9 @@ public function computePodium(ComputePodiumRequest $request) {
6973
return view('admin.podium.result', compact('players', 'from', 'to', 'ladder'));
7074
}
7175

72-
private function getRateLimiterKey() {
73-
return 'compute-podium-win-count:'.auth()->id();
76+
private function getRateLimiterKey()
77+
{
78+
Log::debug('Entering getRateLimiterKey in PodiumController', ['user_id' => auth()->id()]);
79+
return 'compute-podium-win-count:' . auth()->id();
7480
}
7581
}

cncnet-api/app/Http/Controllers/LadderController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ public function getLadderGame(Request $request, $date = null, $cncnetGame = null
261261
$showBothZeroFix = false;
262262
$fixedPointsPreview = [];
263263

264-
if (count($playerGameReports) === 2) {
264+
if (count($playerGameReports) === 2)
265+
{
265266
$p1 = $playerGameReports[0];
266267
$p2 = $playerGameReports[1];
267268

@@ -272,7 +273,8 @@ public function getLadderGame(Request $request, $date = null, $cncnetGame = null
272273
$showBothPositiveFix = $hasOneWinner && $bothPositive;
273274
$showBothZeroFix = $hasOneWinner && $bothZero;
274275

275-
if ($showBothZeroFix && $userIsMod) {
276+
if ($showBothZeroFix && $userIsMod)
277+
{
276278
$fixedPointsPreview = app(\App\Http\Controllers\AdminController::class)->awardedPointsPreview($gameReport, $history);
277279
}
278280
}

cncnet-api/app/Http/Services/ChartService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getHistoriesGamesPlayedByMonth($histories, $ladderId)
4242

4343
public function getPlayerGamesPlayedByMonth($player, $history)
4444
{
45-
return Cache::remember("getPlayerGamesPlayedByMonth/$history->short/$player->id", 5 * 60, function () use ($player, $history)
45+
return Cache::remember("getPlayerGamesPlayedByMonth/$history->short/$player->id", 10 * 60, function () use ($player, $history)
4646
{
4747
$now = $history->starts;
4848
$from = $now->copy()->startOfMonth()->toDateTimeString();

cncnet-api/app/Http/Services/StatsService.php

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function getQmStats(LadderHistory $history, $tierId = 1)
4242

4343
$queuedPlayers = QmQueueEntry::join('qm_match_players', 'qm_match_players.id', '=', 'qm_queue_entries.qm_match_player_id')
4444
->where('ladder_history_id', $history->id)
45+
->where('is_observer', false)
4546
->whereNull('qm_match_id')
4647
->count();
4748

@@ -69,7 +70,7 @@ public function getQmStats(LadderHistory $history, $tierId = 1)
6970

7071
public function getFactionsPlayedByPlayer($player, $history)
7172
{
72-
return Cache::remember("getFactionsPlayedByPlayer/$history->short/$player->id", 5 * 60, function () use ($player, $history)
73+
return Cache::remember("getFactionsPlayedByPlayer/$history->short/$player->id", 10 * 60, function () use ($player, $history)
7374
{
7475
$now = $history->starts;
7576
$from = $now->copy()->startOfMonth()->toDateTimeString();
@@ -176,50 +177,51 @@ private function getFactionResultsForYR($player, $history, $from, $to)
176177

177178
public function getMapWinLossByPlayer($player, $history)
178179
{
179-
// return Cache::remember("getMapWinLossByPlayer/$history->short/$player->id", 5, function () use ($player, $history)
180-
// {
181-
$now = $history->starts;
182-
$from = $now->copy()->startOfMonth()->toDateTimeString();
183-
$to = $now->copy()->endOfMonth()->toDateTimeString();
184-
185-
$playerGamesByMaps = $player->playerGames()
186-
->where("ladder_history_id", $history->id)
187-
->whereBetween("player_game_reports.created_at", [$from, $to])
188-
->groupBy("scen")
189-
->get();
190-
191-
$mapResults = [];
192-
foreach ($playerGamesByMaps as $pg)
180+
// 10 mins cache, this is pretty heavy?
181+
return Cache::remember("getMapWinLossByPlayer/$history->short/$player->id", 10 * 60, function () use ($player, $history)
193182
{
194-
$mapWins = $player->playerGames()
195-
->where("ladder_history_id", $history->id)
196-
->whereBetween("player_game_reports.created_at", [$from, $to])
197-
->where("scen", $pg->scen)
198-
->where("won", true)
199-
->count();
200-
201-
$mapLosses = $player->playerGames()
202-
->where("ladder_history_id", $history->id)
203-
->whereBetween("player_game_reports.created_at", [$from, $to])
204-
->where("scen", $pg->scen)
205-
->where("won", false)
206-
->count();
183+
$now = $history->starts;
184+
$from = $now->copy()->startOfMonth()->toDateTimeString();
185+
$to = $now->copy()->endOfMonth()->toDateTimeString();
207186

208-
$mapTotal = $player->playerGames()
187+
$playerGamesByMaps = $player->playerGames()
209188
->where("ladder_history_id", $history->id)
210189
->whereBetween("player_game_reports.created_at", [$from, $to])
211-
->where("scen", $pg->scen)
212-
->count();
190+
->groupBy("scen")
191+
->get();
213192

214-
$mapResults[$pg->scen] = [
215-
"map" => $pg->game->map,
216-
"won" => $mapWins,
217-
"lost" => $mapLosses,
218-
"total" => $mapTotal
219-
];
220-
}
221-
return $mapResults;
222-
// });
193+
$mapResults = [];
194+
foreach ($playerGamesByMaps as $pg)
195+
{
196+
$mapWins = $player->playerGames()
197+
->where("ladder_history_id", $history->id)
198+
->whereBetween("player_game_reports.created_at", [$from, $to])
199+
->where("scen", $pg->scen)
200+
->where("won", true)
201+
->count();
202+
203+
$mapLosses = $player->playerGames()
204+
->where("ladder_history_id", $history->id)
205+
->whereBetween("player_game_reports.created_at", [$from, $to])
206+
->where("scen", $pg->scen)
207+
->where("won", false)
208+
->count();
209+
210+
$mapTotal = $player->playerGames()
211+
->where("ladder_history_id", $history->id)
212+
->whereBetween("player_game_reports.created_at", [$from, $to])
213+
->where("scen", $pg->scen)
214+
->count();
215+
216+
$mapResults[$pg->scen] = [
217+
"map" => $pg->game->map,
218+
"won" => $mapWins,
219+
"lost" => $mapLosses,
220+
"total" => $mapTotal
221+
];
222+
}
223+
return $mapResults;
224+
});
223225
}
224226

225227
public function getWinnerOfTheDay(LadderHistory $history)

0 commit comments

Comments
 (0)