1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Support query counter in webapp as well as API

This commit is contained in:
Hillel Coren 2016-05-13 12:08:41 +03:00
parent 02b0840215
commit fba37171ae
3 changed files with 53 additions and 24 deletions

View File

@ -67,10 +67,6 @@ class BaseAPIController extends Controller
} else {
$this->manager->setSerializer(new ArraySerializer());
}
if (Utils::isNinjaDev()) {
\DB::enableQueryLog();
}
}
protected function handleAction($request)
@ -166,12 +162,6 @@ class BaseAPIController extends Controller
protected function response($response)
{
if (Utils::isNinjaDev()) {
$count = count(\DB::getQueryLog());
Log::info(Request::method() . ' - ' . Request::url() . ": $count queries");
Log::info(json_encode(\DB::getQueryLog()));
}
$index = Request::get('index') ?: 'data';
if ($index == 'none') {

View File

@ -17,6 +17,7 @@ class Kernel extends HttpKernel {
'Illuminate\View\Middleware\ShareErrorsFromSession',
'App\Http\Middleware\VerifyCsrfToken',
'App\Http\Middleware\DuplicateSubmissionCheck',
'App\Http\Middleware\QueryLogging',
'App\Http\Middleware\StartupCheck',
];

View File

@ -0,0 +1,38 @@
<?php namespace App\Http\Middleware;
use DB;
use Log;
use Utils;
use Closure;
class QueryLogging
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Enable query logging for development
if (Utils::isNinjaDev()) {
DB::enableQueryLog();
}
$response = $next($request);
if (Utils::isNinjaDev()) {
// hide requests made by debugbar
if (strstr($request->url(), '_debugbar') === false) {
$queries = DB::getQueryLog();
$count = count($queries);
Log::info($request->method() . ' - ' . $request->url() . ": $count queries");
//Log::info(json_encode($queries));
}
}
return $response;
}
}