<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Monitor; use Illuminate\Database\Events\QueryExecuted; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use ModStart\Core\Util\ArrayUtil; class DatabaseMonitor { private static $queryCountPerRequest = 0; private static $queryCountPerRequestSqls = array(); public static function init() { goto g874c; aThhg: self::$queryCountPerRequest = 0; goto o9Mcl; dx9Ff: try { DB::listen(function ($vw3jY, $h3lp0 = null, $CoZv2 = null, $Faw6k = null) { self::$queryCountPerRequest++; $FR5o5 = $vw3jY; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto XqtX0; AGadr: $h3lp0 = $vw3jY->bindings; goto V1vEu; XqtX0: $FR5o5 = $vw3jY->sql; goto AGadr; V1vEu: $CoZv2 = $vw3jY->time; goto TkO5l; TkO5l: } self::$queryCountPerRequestSqls[] = array('sql' => $FR5o5, 'bindings' => $h3lp0); if ($CoZv2 > config('modstart.trackLongSqlThreshold', 5000)) { Log::warning("LONG_SQL {$CoZv2}ms, {$FR5o5}, " . ArrayUtil::serializeForLog($h3lp0)); } }); } catch (\Exception $SwVsw) { } goto AFq5p; g874c: if (!config('modstart.trackPerformance', false)) { return; } goto aThhg; o9Mcl: self::$queryCountPerRequestSqls = array(); goto dx9Ff; AFq5p: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $tMyPy => $Q0rz2) { if (is_array($Q0rz2)) { $h3lp0 = ArrayUtil::serializeForLog($Q0rz2['bindings']); self::$queryCountPerRequestSqls[$tMyPy] = $Q0rz2['sql'] . ', ' . $h3lp0; } } return self::$queryCountPerRequestSqls; } }