Skip to content
PHP Ecosystem
Explore

NPlusOneDetector

API reference › Debug Core › Panel › Db › NPlusOneDetector

final classPHPForge\Debug\Panel\Db\NPlusOneDetector
Sourcesrc/Panel/Db/NPlusOneDetector.php

Detects repeated read queries emitted from one captured call site.

MethodDescriptionDefined by
bySequence() staticIndexes findings by every query sequence they cover, so a grid row can look up its own group.NPlusOneDetector
detect() staticGroups repeated SELECT statements by captured call site and keeps the groups above the threshold.NPlusOneDetector
public static function bySequence(list<PHPForge\Debug\Panel\Db\NPlusOneFinding> $findings): array<int, PHPForge\Debug\Panel\Db\NPlusOneFinding>

Indexes findings by every query sequence they cover, so a grid row can look up its own group.

Parameters

ParameterTypeDescription
$findingslist<NPlusOneFinding>Findings to index.

Returns

array<int, NPlusOneFinding>: Findings keyed by covered query sequence.

public static function detect(list<PHPForge\Debug\Panel\Db\QueryRow> $rows, int $threshold = 3): list<PHPForge\Debug\Panel\Db\NPlusOneFinding>

Groups repeated SELECT statements by captured call site and keeps the groups above the threshold.

Parameters

ParameterTypeDescription
$rowslist<QueryRow>Captured query rows in capture order.
$thresholdintMinimum occurrences a call site needs to be reported; must be at least 2.

Returns

list<NPlusOneFinding>: Findings ordered by count, then total duration, then first sequence.

Throws