Skip to content

Commit 44823ed

Browse files
committed
ENH Disable sorting on queries where sort order doesn't matter
Sorting queries can be slow, especially on large datasets and especially if indexes aren't optimised. We should avoid sorting when the sort order doesn't matter.
1 parent 6bf5bde commit 44823ed

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/Form/MultiLinkField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function loadFrom(DataObject $record): void
138138
}
139139

140140
// Load ids from relation
141-
$value = array_values($relation->getIDList() ?? []);
141+
$value = $relation->sort(null)->column('ID');
142142
parent::setValue($value);
143143
}
144144

src/Tasks/MigrationTaskTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ private function checkForBrokenLinks(): void
388388
foreach ($checkForBrokenLinks as $class => $data) {
389389
$field = $data['field'];
390390
$emptyValue = $data['emptyValue'];
391-
$ids = DataObject::get($class)->filter([$field => $emptyValue])->column('ID');
391+
$ids = DataObject::get($class)->filter([$field => $emptyValue])->sort(null)->column('ID');
392392
$numBroken = count($ids);
393393
$this->output->writeln("Found $numBroken broken links for the '$class' class.");
394394
if ($numBroken > 0) {

0 commit comments

Comments
 (0)