2019-03-26 05:46:08 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
{
|
2020-09-07 01:29:46 +02:00
|
|
|
|
|
|
|
$timeStart = microtime(true);
|
|
|
|
|
2019-03-26 05:46:08 +01:00
|
|
|
// Enable query logging for development
|
2019-12-30 22:59:12 +01:00
|
|
|
if (config('ninja.app_env') != 'production') {
|
2019-03-26 05:46:08 +01:00
|
|
|
DB::enableQueryLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $next($request);
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if (config('ninja.app_env') != 'production') {
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
// hide requests made by debugbar
|
|
|
|
if (strstr($request->url(), '_debugbar') === false) {
|
|
|
|
$queries = DB::getQueryLog();
|
|
|
|
$count = count($queries);
|
|
|
|
$timeEnd = microtime(true);
|
|
|
|
$time = $timeEnd - $timeStart;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
|
|
|
Log::info($request->method().' - '.$request->url().": $count queries - ".$time);
|
|
|
|
|
2020-09-19 04:15:38 +02:00
|
|
|
// if($count > 50)
|
|
|
|
// Log::info($queries);
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-03-26 05:46:08 +01:00
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|