fix(LdRepository): restore filtered items when optimistic filters broaden#71
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes optimistic filtering in LdRepository so that items previously marked as filteredOut are restored to loaded when filters broaden, and ensures mutex release is handled safely during the optimistic update pass.
Changes:
- Reworks
applyOptimisticFilterAndSorting()to recompute filter applicability for all in-memory loaded items each time filters/sorts change. - Restores items from
LdPaginatorItemState.filteredOuttoLdPaginatorItemState.loadedwhen they match again. - Wraps the update path in
try/finallyto guarantee mutex release.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… retain filtered-out items
fd271b2 to
4b1080b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/liquid_flutter/lib/src/list/list_paginator.dart:282
- With the repository change that can leave
_itemspopulated withfilteredOutentries whiletotalItems == 0,refreshList()will enter thetotalItems == 0fetch branch without clearing those existing entries. BecauseLdListWidgetonly fetches whengetItemAt(position)isnull(orpendingRefresh), stalefilteredOutitems occupying positions can block placeholder fetches and lead to incorrect data being shown/hidden after refresh. Consider resetting/clearing (or at least removingfilteredOutentries) before the initial fetch whentotalItems == 0so indices represent the refreshed dataset.
Future<void> refreshList() async {
for (final item in _items.entries) {
if (item.value.value != null && item.value.state != LdPaginatorItemState.filteredOut) {
_items[item.key] = item.value.copyWith(state: LdPaginatorItemState.pendingRefresh);
}
}
_updated(null);
// The list has not been fetched yet or we filtered out all the items
// optimistically.
if (totalItems == 0 || _items.isEmpty) {
_setBusy(true);
_offsetQueue.clear();
await fetchItemsAtOffset(initialOffset);
_setBusy(false);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…o enhance restore efficiency
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This fixes an issue in optimistic filtering where filtering only worked in one direction.
Problem
When a filter became stricter, non-matching items were correctly hidden.
But when the filter was broadened again, those items often didn’t come back right away. In practice, users had to fully clear the filter or refresh to see them again.
Root cause
The optimistic filter/sort pass in
repository.dartwasn’t consistently rebuilding item visibility from the current in-memory paginator state.Items that had already moved to
filteredOutcould stay stuck there.What changed
applyOptimisticFilterAndSorting()to recompute filter state for all loaded items on each change.LdPaginatorItemState.filteredOuttoLdPaginatorItemState.loadedas soon as they match again.try/finally) around the update path.Result
Optimistic filtering now behaves correctly in both directions:
No public API changes.