wip fix
This commit is contained in:
1 parent
9bcd4432c6
commit
6f92f9e1d5
1209 files changed
+220940
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports\Helper;
|
||||
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class ImportBenchmark
|
||||
{
|
||||
public static float $benchmarkStartTime;
|
||||
|
||||
public static int $benchmarkStartMemory;
|
||||
|
||||
public static int $startRowCount;
|
||||
|
||||
public static int $startQueries;
|
||||
|
||||
public static function start(string $table): void
|
||||
{
|
||||
self::$startRowCount = DB::connection('mongodb')->table($table)->count();
|
||||
self::$benchmarkStartTime = microtime(true);
|
||||
self::$benchmarkStartMemory = memory_get_usage();
|
||||
DB::connection('mongodb')->enableQueryLog();
|
||||
}
|
||||
|
||||
public static function end(string $table): void
|
||||
{
|
||||
$executionTime = microtime(true) - self::$benchmarkStartTime;
|
||||
$memoryUsage = round((memory_get_usage() - self::$benchmarkStartMemory) / 1024 / 1024, 2);
|
||||
|
||||
$logs = DB::connection('mongodb')->getQueryLog();
|
||||
$queriesCount = \count($logs);
|
||||
|
||||
// Get row count after we've stopped tracking queries
|
||||
$rowDiff = DB::connection('mongodb')->table($table)->count() - self::$startRowCount;
|
||||
|
||||
$formattedTime = match (true) {
|
||||
$executionTime >= 60 => sprintf('%dm %ds', floor($executionTime / 60), $executionTime % 60),
|
||||
$executionTime >= 1 => round($executionTime, 2).'s',
|
||||
default => round($executionTime * 1000).'ms',
|
||||
};
|
||||
|
||||
$str = '⚡ TIME: '.$formattedTime;
|
||||
$str .= '<br/>MEM: '.$memoryUsage.'MB';
|
||||
$str .= '<br/>SQL: '.number_format($queriesCount);
|
||||
$str .= '<br/>ROWS: '.number_format($rowDiff);
|
||||
|
||||
$recipient = Auth::user();
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Import compleated')
|
||||
->body(new HtmlString($str))
|
||||
->sendToDatabase($recipient);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user