Limit with DataList::filterByCallback is inconsistent.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by tracing the DataList limit and filterByCallback entry points, then reproduce the three Page::get() examples from the issue. Compare the returned counts and query order; done means the documented limit and callback combinations produce consistent, expected results without unnecessary filtering.
Written by the indexing model from the issue text.
Description
Affected Version: 4.9+
Description
If you call limit on a DataList, and then call filterByCallback, the data query will first be executed, which gets a limited number of results from the database. This limited result set is then filtered using the callback, which may result in even less results being returned.
This was pointed out by @christopherdarling in the below comment, which perhaps explains it a little more clearly:
that's true but this does unearth the issue of the order you call these methods for example;
- if you do
Page::get()->filterByCallback(fn () => true)->limit(10)->count();,filterByCallback()loops over the entire set of Page rows (possibly 1000's) to do the filter comparison even after the 10th valid item is found which isn't necessary. I think this code change avoids that- if you do
Page::get()->limit(10)->filterByCallback(fn ($item) => $item->URLSegment !== 'home')->count();I get 9 records because we're filtering on the 10 records from the database and 1 fails this filter- if you do
Page::get()->reverse()->limit(10)->filterByCallback(fn ($item) => $item->URLSegment !== 'home')->count();I get 10 records (where the filter doesn't remove any rows)
Originally posted by @christopherdarling in https://github.com/silverstripe/silverstripe-framework/issues/10248#issuecomment-1060502492
- Dominant language
- No language data
- Stars
- 7
- Forks
- 74
- Avg merge
- 1d 14m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from silverstripe/developer-docs
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
silverstripe/developer-docs#911 ·
-
Read-only replicas: config key is rule_patterns_must_use_primary_db, not must_use_primary_db_rules Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
silverstripe/developer-docs#909 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
silverstripe/developer-docs#908 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
silverstripe/developer-docs#907 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
silverstripe/developer-docs#903 ·
All issues in silverstripe/developer-docs
Similar issues
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100