Skip to content

Commit a1514f2

Browse files
alexp8GrantBartlettCopilotSneer-ra2rohsyl
authored
Develop to main (#427)
* 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) * remvoe yuri check (#419) * remvoe yuri check * just remove the commented code for now, if need it later, fetch from git history * optimize getRecentLadderGames * Update cncnet-api/app/Http/Services/LadderService.php Co-authored-by: Copilot <[email protected]> * Hotfix for the faction policy service. * Fixed getRecentLadderGames. * monitor duration * removing caching from getRecentLadderGames * add more details in the duration log in matchMeUp * revert max connections back to 500 * Add a missing index on games table * fix missing faction icons * feature/audit log (#411) * first commit * Update cncnet-api/app/Models/UserSettings.php Co-authored-by: Copilot <[email protected]> * remove old api, and add twitch profile to the get active matches * implement getActivitylogOptions * create migration, implement activity logging * add LogsActivity to qmMap * null check just in case --------- Co-authored-by: Copilot <[email protected]> * show observer properly in the recent games box * Pass ladder alert to qm client. * update long query time * fix relationships used in getObservedGames (#426) --------- Co-authored-by: Grant Bartlett <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Sneer <[email protected]> Co-authored-by: rohs <[email protected]>
1 parent 80f3d8f commit a1514f2

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

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

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,19 @@ class AdminController extends Controller
3939
*/
4040
public function getAuditLog(Request $request)
4141
{
42-
if (!$request->user() || !$request->user()->isAdmin()) {
42+
if (!$request->user() || !$request->user()->isAdmin())
43+
{
4344
abort(403);
4445
}
4546

4647
$query = Activity::query();
4748

48-
if ($request->filled('model_type')) {
49+
if ($request->filled('model_type'))
50+
{
4951
$query->where('subject_type', $request->input('model_type'));
5052
}
51-
if ($request->filled('event')) {
53+
if ($request->filled('event'))
54+
{
5255
$query->where('event', $request->input('event'));
5356
}
5457

@@ -61,7 +64,8 @@ public function getAuditLog(Request $request)
6164
*/
6265
public function getObservers(Request $request)
6366
{
64-
if (!$request->user() || !$request->user()->isAdmin()) {
67+
if (!$request->user() || !$request->user()->isAdmin())
68+
{
6569
abort(403);
6670
}
6771
$observers = User::where('group', User::Observer)->get();
@@ -75,7 +79,8 @@ public function getObservers(Request $request)
7579
*/
7680
public function addObserver(Request $request)
7781
{
78-
if (!$request->user() || !$request->user()->isAdmin()) {
82+
if (!$request->user() || !$request->user()->isAdmin())
83+
{
7984
abort(403);
8085
}
8186
$request->validate([
@@ -85,7 +90,8 @@ public function addObserver(Request $request)
8590
$user = User::where('email', $input)
8691
->orWhere('name', $input)
8792
->first();
88-
if ($user) {
93+
if ($user)
94+
{
8995
$user->group = User::Observer;
9096
$user->save();
9197
return redirect()->route('admin.observers')->with('success', 'User added as observer.');
@@ -98,14 +104,16 @@ public function addObserver(Request $request)
98104
*/
99105
public function removeObserver(Request $request)
100106
{
101-
if (!$request->user() || !$request->user()->isAdmin()) {
107+
if (!$request->user() || !$request->user()->isAdmin())
108+
{
102109
abort(403);
103110
}
104111
$request->validate([
105112
'user_id' => 'required|integer|exists:users,id'
106113
]);
107114
$user = User::find($request->input('user_id'));
108-
if ($user && $user->group === User::Observer) {
115+
if ($user && $user->group === User::Observer)
116+
{
109117
$user->group = User::User;
110118
$user->save();
111119
return redirect()->route('admin.observers')->with('success', 'Observer removed.');
@@ -901,7 +909,7 @@ public function unlinkDuplicate(Request $request)
901909
// Helper closure to reset primary_user_id for primary accounts that no longer have duplicates.
902910
// An account is marked as primary by setting its own id as primary_user_id when the first duplicate is linked.
903911
// If the last duplicate is unlinked, primary_user_id should be reset to null.
904-
$maybeClearPrimaryFlag = function (User $primary)
912+
$maybeClearPrimaryFlag = function (User $primary)
905913
{
906914
$hasDuplicates = User::where('primary_user_id', $primary->id)->where('id', '!=', $primary->id)->exists();
907915
if (!$hasDuplicates && $primary->primary_user_id === $primary->id)
@@ -1551,7 +1559,8 @@ public function getPlayerRatings(Request $request, $ladderAbbreviation = null)
15511559
$users = User::join("user_ratings as ur", "ur.user_id", "=", "users.id")
15521560
->orderBy("ur.rating", "DESC")
15531561
->where("ur.ladder_id", $ladder->id)
1554-
->where(function ($query) {
1562+
->where(function ($query)
1563+
{
15551564
$query->whereNull("users.primary_user_id")
15561565
->orWhereColumn("users.primary_user_id", "users.id");
15571566
})
@@ -1564,7 +1573,8 @@ public function getPlayerRatings(Request $request, $ladderAbbreviation = null)
15641573
$users = User::join("user_ratings as ur", "ur.user_id", "=", "users.id")
15651574
->orderBy("ur.rating", "DESC")
15661575
->where("ur.ladder_id", $ladder->id)
1567-
->where(function ($query) {
1576+
->where(function ($query)
1577+
{
15681578
$query->whereNull("users.primary_user_id")
15691579
->orWhereColumn("users.primary_user_id", "users.id");
15701580
})
@@ -1841,40 +1851,37 @@ public function awardedPointsPreview(GameReport $gameReport, LadderHistory $hist
18411851

18421852
public function getObservedGames(Request $request, $ladderAbbreviation = null)
18431853
{
1844-
$ladder = Ladder::where('abbreviation', $ladderAbbreviation)->first();
1854+
$startTime = microtime(true);
18451855

1856+
$ladder = Ladder::where('abbreviation', $ladderAbbreviation)->first();
18461857
if ($ladder == null)
18471858
{
18481859
abort(404, 'Ladder not found');
18491860
}
18501861

18511862
$ladderHistoryShort = $request->query('ladderHistoryShort');
1852-
18531863
if ($ladderHistoryShort)
18541864
{
1855-
$ladderHistory = \App\Models\LadderHistory::where('ladder_id', $ladder->id)
1865+
$ladderHistory = LadderHistory::where('ladder_id', $ladder->id)
18561866
->where('short', $ladderHistoryShort)
18571867
->first();
18581868
}
18591869
else
18601870
{
18611871
$ladderHistory = $ladder->currentHistory();
18621872
}
1863-
18641873
if (!$ladderHistory)
18651874
{
18661875
abort(404, 'Ladder history not found');
18671876
}
18681877

18691878
// list of players and observers from previous games for this ladder history
18701879
$observedGames = Game::with([
1871-
'players.player',
1872-
'players.player.user',
1873-
'observers.player',
1874-
'observers.player.user'
1880+
'players.player.user', // ✅ loads player + user
1881+
'observers.player.user' // ✅ loads observer + user
18751882
])
18761883
->where('ladder_history_id', $ladderHistory->id)
1877-
->whereHas('observers')
1884+
->whereHas('observers') // ✅ only games that actually have observers
18781885
->paginate(10);
18791886

18801887
// to populate a dropdown and user can pick which history to view observed games
@@ -1884,6 +1891,15 @@ public function getObservedGames(Request $request, $ladderAbbreviation = null)
18841891
->select('short')
18851892
->get();
18861893

1894+
$endTime = microtime(true);
1895+
$duration = $endTime - $startTime;
1896+
$durationRounded = round($duration, 1);
1897+
Log::info('getObservedGames duration', [
1898+
'duration_seconds' => $durationRounded,
1899+
'ladderAbbreviation' => $ladderAbbreviation,
1900+
'ladderHistoryShort' => $ladderHistoryShort
1901+
]);
1902+
18871903
return view("admin.observed-games", [
18881904
"observedGames" => $observedGames,
18891905
"ladderHistory" => $ladderHistory,

cncnet-api/app/Http/Controllers/Api/V2/Qm/MatchUpController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private function onMatchMeUp(Request $request, Ladder $ladder, Player $player, ?
248248
}
249249
catch (\RuntimeException $ex)
250250
{
251-
$duration = microtime(true) - $startTime;
251+
$duration = round(microtime(true) - $startTime, 1);
252252
Log::error('Failed to create QM Player: ' . $ex->getMessage() . " | onMatchMeUp exit: exception | duration: {$duration} seconds", [
253253
'player_id' => $player->id,
254254
'username' => $player->username,
@@ -262,7 +262,7 @@ private function onMatchMeUp(Request $request, Ladder $ladder, Player $player, ?
262262

263263
if (!$validSides)
264264
{
265-
$duration = microtime(true) - $startTime;
265+
$duration = round(microtime(true) - $startTime, 1);
266266
Log::info("onMatchMeUp exit: invalid side | duration: {$duration} seconds", [
267267
'player_id' => $player->id,
268268
'username' => $player->username,
@@ -280,7 +280,7 @@ private function onMatchMeUp(Request $request, Ladder $ladder, Player $player, ?
280280
{
281281
$qmPlayer->ai_dat = $request->ai_dat;
282282
$qmPlayer->save();
283-
$duration = microtime(true) - $startTime;
283+
$duration = round(microtime(true) - $startTime, 1);
284284
Log::info("onMatchMeUp exit: ai_dat error | duration: {$duration} seconds", [
285285
'player_id' => $player->id,
286286
'username' => $player->username,
@@ -318,7 +318,7 @@ private function onMatchMeUp(Request $request, Ladder $ladder, Player $player, ?
318318
$spawnStruct = QuickMatchSpawnService::createSpawnStruct($qmMatch, $qmPlayer, $ladder, $ladder->qmLadderRules);
319319
$spawnStruct = QuickMatchSpawnService::addQuickMatchAISpawnIni($spawnStruct, $ladder, AIHelper::BRUTAL_AI);
320320

321-
$duration = microtime(true) - $startTime;
321+
$duration = round(microtime(true) - $startTime, 1);
322322
Log::info("onMatchMeUp exit: ai match | duration: {$duration} seconds", [
323323
'player_id' => $player->id,
324324
'username' => $player->username,
@@ -353,7 +353,7 @@ private function onMatchMeUp(Request $request, Ladder $ladder, Player $player, ?
353353

354354
$qmPlayer->touch();
355355

356-
$duration = microtime(true) - $startTime;
356+
$duration = round(microtime(true) - $startTime, 1);
357357
Log::info("onMatchMeUp exit: queued opponent | duration: {$duration} seconds", [
358358
'player_id' => $player->id,
359359
'username' => $player->username,
@@ -381,7 +381,7 @@ private function onMatchMeUp(Request $request, Ladder $ladder, Player $player, ?
381381
$qmPlayer->waiting = false;
382382
$qmPlayer->save();
383383
Log::info("MatchUpController ** Player Check: QMPlayer: $qmPlayer - QMMatch: $qmMatch");
384-
$duration = microtime(true) - $startTime;
384+
$duration = round(microtime(true) - $startTime, 1);
385385
Log::info("onMatchMeUp exit: not enough players | duration: {$duration} seconds", [
386386
'player_id' => $player->id,
387387
'username' => $player->username,
@@ -423,7 +423,7 @@ private function onMatchMeUp(Request $request, Ladder $ladder, Player $player, ?
423423
$qmPlayer->waiting = false;
424424
$qmPlayer->save();
425425

426-
$duration = microtime(true) - $startTime;
426+
$duration = round(microtime(true) - $startTime, 1);
427427
Log::info("onMatchMeUp exit: match found | duration: {$duration} seconds", [
428428
'player_id' => $player->id,
429429
'username' => $player->username,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function getHistoriesGamesPlayedByMonth($histories, $ladderId)
2424
->get();
2525

2626
$labels = [];
27+
$results = [];
2728
foreach ($games as $hour => $game)
2829
{
2930
$hourFormatted = Carbon::create(null, null, null, $hour);

cncnet-api/app/Models/Game.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ public function observers()
110110
{
111111
return $this->hasMany(PlayerGameReport::class, 'game_report_id', 'game_report_id')
112112
->where('spectator', true)
113-
->with(['player', 'user']);
113+
->with(['player.user']);
114114
}
115115

116116

117117
public function players()
118118
{
119119
return $this->hasMany(PlayerGameReport::class, 'game_report_id', 'game_report_id')
120120
->where('spectator', false)
121-
->with('player');
121+
->with('player.user');
122122
}
123123
}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ services:
8282
image: mariadb:latest
8383
container_name: cncnet_ladder_mysql${ENV_SUFFIX}
8484
restart: unless-stopped
85-
command: --max_connections=500 --max_allowed_packet=128M --log_warnings=3 --wait_timeout=600 --slow-query-log --interactive_timeout=600 --long_query_time=2
85+
command: --max_connections=500 --max_allowed_packet=128M --log_warnings=3 --wait_timeout=600 --slow-query-log --interactive_timeout=600 --long_query_time=0.5
8686
environment:
8787
MYSQL_DATABASE: ${MYSQL_DATABASE}
8888
MYSQL_USER: ${MYSQL_USER}

0 commit comments

Comments
 (0)