cakephp / debug_kit

Debug Toolbar for CakePHP applications.
http://cakephp.org
Other
852 stars 573 forks source link

CakePHP 5 + Elasticsearch 4 - Warning : Undefined array key "took" #989

Closed Christopher-HM closed 9 months ago

Christopher-HM commented 9 months ago

Hello @LordSimal,

For certain queries the "took" key is not returned in the response.

Here is a small correction to apply in the \DebugKit\Database\Log\DebugLog.php file:

        // This specific to Elastic Search
        if (!$query instanceof LoggedQuery && isset($context['request']) && isset($context['response'])) {
            $took = $context['response']['took'] ?? 0; // Added !!!
            $this->_totalTime += $took; // Modified !!!

            $this->_queries[] = [
                'query' => json_encode([
                    'method' => $context['request']['method'],
                    'path' => $context['request']['path'],
                    'data' => $context['request']['data'],
                ], JSON_PRETTY_PRINT),
                'took' => $took, // Modified !!!
                'rows' => $context['response']['hits']['total']['value'] ?? $context['response']['hits']['total'] ?? 0,
            ];

            return;
        }

CaptureDebugKit

Thanks!