Skip to content

Commit 76e30a9

Browse files
ENH Disable sorting on queries where sort order doesn't matter (#405)
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 8977b54 commit 76e30a9

3 files changed

Lines changed: 7 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->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) {

tests/behat/features/create-edit-linkfield.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ I want to add links to pages, files, external URLs, email addresses and phone nu
181181
Then I should not see "Email link" in the "[data-field-id='Form_EditForm_HasOneLink']" element
182182
Then I press the "Publish" button
183183

184+
# Test that order is retained after refreshing
185+
When I reload the page
186+
Then I should see "All about us" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link--is-last" element
187+
And I should see "External URL" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link--is-first" element
188+
184189
Scenario: Create file link with nested redux form
185190
When I click on the "[data-field-id='Form_EditForm_HasManyLinks'] button" element
186191
Then I should see "Link to a file" in the "[data-field-id='Form_EditForm_HasManyLinks'] .dropdown-item:nth-of-type(2)" element

0 commit comments

Comments
 (0)