Skip to content

NEW Allow filtering and excluding based on another list#11804

Merged
emteknetnz merged 3 commits intosilverstripe:6from
creative-commoners:pulls/6/filterbylist
Aug 6, 2025
Merged

NEW Allow filtering and excluding based on another list#11804
emteknetnz merged 3 commits intosilverstripe:6from
creative-commoners:pulls/6/filterbylist

Conversation

@GuySartorelli
Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli commented Jul 28, 2025

Important

There are multiple commits. DO NOT SQUASH

  1. Introduce the new API and deprecate old API
  2. Start using the new methods where possible to reduce the number of queries
  3. Replace usages of deprecated methods with the new replacements

This provides a convenient shortcut for e.g. filtering a list of pages by the IDs of a relation, where the relation IDs come from a separate pre-filtered query.

Using this instead of executing the first query and filtering by IDs (or by other fields) allows the database optimiser to optimise a joint query and reduces latency overhead of performing separate queries.

Issue

Comment thread src/Forms/GridField/GridFieldGroupDeleteAction.php
Comment thread src/Forms/GridField/GridFieldGroupDeleteAction.php
Comment thread src/Forms/GridField/GridFieldGroupDeleteAction.php
@GuySartorelli GuySartorelli force-pushed the pulls/6/filterbylist branch from 039ed54 to ad2cbf5 Compare July 29, 2025 00:44
Comment thread src/Security/Permission.php Outdated
Comment thread src/Security/Permission.php
Comment thread src/ORM/DataList.php Outdated
Comment thread src/ORM/DataList.php Outdated
Comment thread src/ORM/Connect/Database.php Outdated
Comment thread src/ORM/EagerLoadedList.php Outdated
@GuySartorelli GuySartorelli force-pushed the pulls/6/filterbylist branch 3 times, most recently from dfb00a9 to 0b4c27a Compare August 4, 2025 02:55
@GuySartorelli GuySartorelli marked this pull request as ready for review August 4, 2025 03:03
Comment thread src/Forms/GridField/GridFieldAddExistingAutocompleter.php
Comment thread src/Forms/GridField/GridFieldGroupDeleteAction.php
Comment thread src/ORM/Connect/Database.php Outdated
Comment thread src/ORM/Connect/MySQLDatabase.php Outdated
Comment thread src/ORM/Connect/Database.php
Comment thread src/ORM/EagerLoadedList.php
Comment thread src/Security/Permission.php Outdated
Comment thread src/Security/Permission.php Outdated
Comment thread src/Security/Permission.php Outdated
Comment thread tests/php/ORM/DataListTest.php Outdated
Comment thread src/ORM/EagerLoadedList.php Outdated
*/
public function filterByList(SS_List $list, string $fieldToFilterBy = 'ID', string $fieldInOtherList = 'ID'): static
{
$thisDataClass = $this->dataClass();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not a trait, then do as a private method, similar to DataList

Comment thread src/ORM/EagerLoadedList.php Outdated
*/
public function excludeByList(SS_List $list, string $fieldToFilterBy = 'ID', string $fieldInOtherList = 'ID'): static
{
$thisDataClass = $this->dataClass();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as as linked comment, all of it if viable assuming you can tolerate a dynamic method call

Comment thread src/ORM/EagerLoadedList.php
This provides a convenient shortcut for e.g. filtering a list of pages
by the IDs of a relation, where the relation IDs come from a separate
pre-filtered query.

Using this instead of executing the first query and filtering by IDs
allows the database optimiser to optimise a joint query and reduces
latency overhead of performing separate queries.
Some queries can be combined using the new filterByList and
excludeByList queries on DataList. This reduces latency overhead and
provides an opportunity for the database optimiser to do its thing
@emteknetnz emteknetnz merged commit 0a780af into silverstripe:6 Aug 6, 2025
12 checks passed
@emteknetnz emteknetnz deleted the pulls/6/filterbylist branch August 6, 2025 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants