Skip to content

Commit c774507

Browse files
alexp8claude
andauthored
Develop (#528)
* Add points field to daily stats API and optimize query performance (#523) * Add points field to daily stats API and optimize query performance Reduces database queries from 3 to 1 by replacing correlated subqueries with eager loading and PHP-based aggregation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * show streamer name --------- Co-authored-by: Claude <noreply@anthropic.com> * Refactor player stats to service layer and add monthly stats endpoint Extracted player time-range stats logic from controller to StatsService for better separation of concerns and reusability. Changes: - Add StatsService::getPlayerTimeRangeStats() method for flexible time-range queries - Refactor getPlayerDailyStats to use service (reduced from ~80 to ~45 lines) - Add new getPlayerMonthlyStats endpoint at /api/v1/ladder/{game}/player/{player}/month - Consistent caching strategy (5 min) for both daily and monthly stats 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix bug * show qm map description --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0a3f154 commit c774507

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ public function getGameWithReports(
3737
'report.playerGameReports.stats.gameObjectCounts.countableGameObject', // CRITICAL: Eliminates N+1 for cameo stats
3838
'report.playerGameReports.clan',
3939
'report.playerGameReports.gameReport', // Needed for clan logic in views
40-
'report.game.qmMatch.map', // Needed for map preview
40+
'report.game.qmMap.map', // Needed for map preview (persists after qm_matches pruning)
41+
'report.game.qmMatch.map', // Needed for map preview (legacy, backward compatibility)
4142

42-
// QM Match data (available to all users for connection stats)
43+
// QM Map data (direct relationship, persists after qm_matches pruning)
44+
'qmMap.map',
45+
46+
// QM Match data (legacy, for backward compatibility)
4347
'qmMatch.qmConnectionStats',
4448
'qmMatch.map',
4549
];

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,16 @@ public function getRecentLadderGames(LadderHistory $history, $limit = 4)
423423
return Game::where("ladder_history_id", $history->id)
424424
->whereNotNull('game_report_id')
425425
->orderByDesc("id")
426-
->select(['id', 'ladder_history_id', 'game_report_id', 'qm_match_id', 'hash', 'game_type', 'updated_at'])
426+
->select(['id', 'ladder_history_id', 'game_report_id', 'qm_match_id', 'qm_map_id', 'hash', 'game_type', 'updated_at'])
427427
->with([
428428
'report:id,game_id,duration,fps',
429429
'report.playerGameReports:game_report_id,player_id,clan_id,points,stats_id,won,spectator',
430430
'report.playerGameReports.player:id,username',
431431
'report.playerGameReports.player.qmPlayer:id,player_id,team',
432432
'report.playerGameReports.clan:id,short',
433433
'report.playerGameReports.stats:id,sid,cty',
434+
'qmMap:id,description,map_id',
435+
'qmMap.map:id,name,hash,image_path,image_hash,filename',
434436
'qmMatch:id,qm_map_id',
435437
'qmMatch.map:id,description,map_id',
436438
'qmMatch.map.map:id,name,hash,image_path,image_hash,filename',
@@ -477,7 +479,11 @@ private function getGamesListingEagerLoads(): array
477479
'report.playerGameReports.player.user.userSettings:user_id,is_anonymous', // For getUserAvatar() anonymous check
478480
'report.playerGameReports.stats:id,cty,sid', // For faction() method - needs cty (YR) and sid (other games)
479481

480-
// QM Match and map data
482+
// QM Map data (direct relationship, persists after qm_matches pruning)
483+
'qmMap:id,description,map_id',
484+
'qmMap.map:id,name,hash,image_path,image_hash',
485+
486+
// QM Match and map data (legacy, for backward compatibility)
481487
'qmMatch:id,qm_map_id',
482488
'qmMatch.map:id,description,map_id',
483489
'qmMatch.map.map:id,name,hash,image_path,image_hash',
@@ -496,6 +502,7 @@ public function getRecentLadderGamesPaginated($date, $cncnetGame)
496502
'games.id',
497503
'games.game_report_id',
498504
'games.qm_match_id',
505+
'games.qm_map_id',
499506
'games.ladder_history_id',
500507
'games.updated_at'
501508
)
@@ -534,7 +541,8 @@ public function getRecentErrorLadderGamesPaginated($date, $cncnetGame)
534541
'scen',
535542
'hash',
536543
'game_report_id',
537-
'qm_match_id'
544+
'qm_match_id',
545+
'qm_map_id'
538546
)
539547
->where("ladder_history_id", "=", $history->id)
540548
->where('game_reports.duration', '=', 3)

0 commit comments

Comments
 (0)