Skip to content

Commit

Permalink
Merge 60bd5dc into 6af8eed
Browse files Browse the repository at this point in the history
  • Loading branch information
v-porytskyi committed Aug 3, 2023
2 parents 6af8eed + 60bd5dc commit 88f1c0f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/QueryDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@ public function logQuery($query, Collection $backtrace)
return Arr::get($trace, 'function') === 'getRelationValue' || Arr::get($trace, 'class') === Relation::class ;
});

if ($relation == null) {
$q = $backtrace->first();
if ($q !== null && isset($q['args'][0]))
{
/** @var \Illuminate\Database\Events\QueryExecuted $query */
$query = $backtrace->first()['args'][0];

$model = $q['class'];

$relationName = null;
$relatedModel = $relationName;

$sources = $this->findSource($backtrace);

$key = md5($query->sql . $model . $relationName . $sources[0]->name . $sources[0]->line);

$count = Arr::get($this->queries, $key.'.count', 0);
$time = Arr::get($this->queries, $key.'.time', 0);

$this->queries[$key] = [
'count' => ++$count,
'time' => $time + $query->time,
'query' => $query->sql,
'model' => $model,
'relatedModel' => $relatedModel,
'relation' => $relationName,
'sources' => $sources
];
}
}

// We try to access a relation
if (is_array($relation) && isset($relation['object'])) {
if ($relation['class'] === Relation::class) {
Expand Down

0 comments on commit 88f1c0f

Please sign in to comment.