Skip to content

Commit

Permalink
Index fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Nov 6, 2023
1 parent 1327f15 commit 628eaaa
Show file tree
Hide file tree
Showing 149 changed files with 1,144 additions and 1,033 deletions.
22 changes: 15 additions & 7 deletions app/Http/Controllers/Admin/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getOnlinePlayersOverTime(Request $request)
}
$sqlData = $query->get();
$sqlData = $sqlData->map(function ($item) {
$item->created_at_5min = (int)$item->created_at_5min;
$item->created_at_5min = (int) $item->created_at_5min;

return array_values(get_object_vars($item));
})->toArray();
Expand Down Expand Up @@ -265,7 +265,7 @@ public function getServerPerformanceOverTime(Request $request)
->whereIn('server_id', $servers->pluck('id'));
$sqlData = $query->get();
$sqlData = $sqlData->map(function ($item) {
$item->created_at_5min = (int)$item->created_at_5min;
$item->created_at_5min = (int) $item->created_at_5min;
$item->used_memory = round($item->used_memory / 1024); // Convert to MB

return array_values(get_object_vars($item));
Expand Down Expand Up @@ -308,7 +308,7 @@ public function getServerOnlineActivityOverTime(Request $request)
->whereIn('server_id', $servers->pluck('id'));
$sqlData = $query->get();
$sqlData = $sqlData->map(function ($item) {
$item->created_at_5min = (int)$item->created_at_5min;
$item->created_at_5min = (int) $item->created_at_5min;

return array_values(get_object_vars($item));
})->toArray();
Expand All @@ -323,13 +323,14 @@ public function getServerOnlineActivityOverTime(Request $request)
public function getPlayerMinecraftVersions(Request $request)
{
$isAuthorized = $request->user()->can('view admin_dashboard') || $request->user()->can('view server_intel');
if (!$isAuthorized) {
if (! $isAuthorized) {
abort(403);
}

$request->validate([
'servers' => 'sometimes|nullable|array',
'servers.*' => 'sometimes|nullable|integer|exists:servers,id',
'top' => 'sometimes|nullable|integer',
]);

$servers = $request->query('servers') ?? null;
Expand All @@ -344,6 +345,9 @@ public function getPlayerMinecraftVersions(Request $request)
->whereIn('server_id', $servers->pluck('id'))
->groupBy('minecraft_version')
->orderBy('count', 'desc')
->when($request->query('top'), function ($query, $top) {
return $query->limit($top);
})
->get()
->map(function ($item) {
return [
Expand All @@ -358,13 +362,14 @@ public function getPlayerMinecraftVersions(Request $request)
public function getPlayerJoinAddresses(Request $request)
{
$isAuthorized = $request->user()->can('view admin_dashboard') || $request->user()->can('view server_intel');
if (!$isAuthorized) {
if (! $isAuthorized) {
abort(403);
}

$request->validate([
'servers' => 'sometimes|nullable|array',
'servers.*' => 'sometimes|nullable|integer|exists:servers,id',
'top' => 'sometimes|nullable|integer',
]);

$servers = $request->query('servers') ?? null;
Expand All @@ -379,6 +384,9 @@ public function getPlayerJoinAddresses(Request $request)
->whereIn('server_id', $servers->pluck('id'))
->groupBy('join_address')
->orderBy('count', 'desc')
->when($request->query('top'), function ($query, $top) {
return $query->limit($top);
})
->get()
->map(function ($item) {
return [
Expand Down Expand Up @@ -438,7 +446,7 @@ public function getPlayerJoinAddressesOverTime(Request $request)
foreach ($dataSets as $address => $dataSet) {
foreach ($uniqueDates as $date) {
$day = $date->unix_day * 1000;
if (!isset($dataSet[$day])) {
if (! isset($dataSet[$day])) {
$dataSets[$address][$day] = 0;
}
}
Expand Down Expand Up @@ -513,7 +521,7 @@ public function getPlayerMinecraftVersionsOverTime(Request $request)
foreach ($dataSets as $version => $dataSet) {
foreach ($uniqueDates as $date) {
$day = $date->unix_day * 1000;
if (!isset($dataSet[$day])) {
if (! isset($dataSet[$day])) {
$dataSets[$version][$day] = 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('minecraft_player_events', function (Blueprint $table) {
$table->index('created_at');
});

Schema::table('minecraft_player_deaths', function (Blueprint $table) {
$table->index('created_at');
$table->index('died_at');
});

Schema::table('minecraft_player_pvp_kills', function (Blueprint $table) {
$table->index('created_at');
$table->index('killed_at');
});

Schema::table('minecraft_player_world_stats', function (Blueprint $table) {
$table->index('created_at');
});

Schema::table('minecraft_players', function (Blueprint $table) {
$table->index('created_at');
$table->index('first_seen_at');
$table->index('last_seen_at');
});

Schema::table('players', function (Blueprint $table) {
$table->index('created_at');
$table->index('first_seen_at');
$table->index('last_seen_at');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('minecraft_player_events', function (Blueprint $table) {
$table->dropIndex(['created_at']);
});

Schema::table('minecraft_player_deaths', function (Blueprint $table) {
$table->dropIndex(['created_at']);
$table->dropIndex(['died_at']);
});

Schema::table('minecraft_player_pvp_kills', function (Blueprint $table) {
$table->dropIndex(['created_at']);
$table->dropIndex(['killed_at']);
});

Schema::table('minecraft_player_world_stats', function (Blueprint $table) {
$table->dropIndex(['created_at']);
});

Schema::table('minecraft_players', function (Blueprint $table) {
$table->dropIndex(['created_at']);
$table->dropIndex(['first_seen_at']);
$table->dropIndex(['last_seen_at']);
});

Schema::table('players', function (Blueprint $table) {
$table->dropIndex(['created_at']);
$table->dropIndex(['first_seen_at']);
$table->dropIndex(['last_seen_at']);
});
}
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 628eaaa

Please sign in to comment.