Zum Inhalt springen

Order by before where (ARCH7076)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key php.performance.orderby-before-where · Severity warning · Category performance

Sorting before filtering wastes work by ordering rows that are later discarded. Filter first, then sort the smaller result.

<?php
$result = collect($orders)
->sortBy('total')
->filter(fn ($o) => $o->status === 'paid')
->values();
<?php
$result = collect($orders)
->filter(fn ($o) => $o->status === 'paid')
->sortBy('total')
->values();

Move the sort after the filter step so only the smaller, needed set is ordered.