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 .= '
MEM: '.$memoryUsage.'MB';
$str .= '
SQL: '.number_format($queriesCount);
$str .= '
ROWS: '.number_format($rowDiff);
$recipient = Auth::user();
Notification::make()
->success()
->title('Import compleated')
->body(new HtmlString($str))
->sendToDatabase($recipient);
}
}