2019-03-26 05:46:08 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use DB;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Log;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class QueryLogging.
|
|
|
|
*/
|
|
|
|
class QueryLogging
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Closure $next
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle(Request $request, Closure $next)
|
|
|
|
{
|
|
|
|
// Enable query logging for development
|
|
|
|
if(config('ninja.app_env') != 'production') {
|
|
|
|
DB::enableQueryLog();
|
|
|
|
$timeStart = microtime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $next($request);
|
|
|
|
|
|
|
|
if(config('ninja.app_env') != 'production') {
|
|
|
|
|
|
|
|
// hide requests made by debugbar
|
|
|
|
if (strstr($request->url(), '_debugbar') === false) {
|
|
|
|
$queries = DB::getQueryLog();
|
|
|
|
$count = count($queries);
|
|
|
|
$timeEnd = microtime(true);
|
|
|
|
$time = $timeEnd - $timeStart;
|
2019-09-11 05:46:23 +02:00
|
|
|
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
|
2019-04-25 09:16:41 +02:00
|
|
|
|
2019-10-17 07:09:52 +02:00
|
|
|
// if($count > 50)
|
|
|
|
// Log::info($queries);
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|