Skip to content

fix: add stable sort to collection media pagination query#2444

Merged
enoch85 merged 10 commits into
mainfrom
fix/collection-pagination-duplicates
Mar 24, 2026
Merged

fix: add stable sort to collection media pagination query#2444
enoch85 merged 10 commits into
mainfrom
fix/collection-pagination-duplicates

Conversation

@enoch85

@enoch85 enoch85 commented Mar 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a secondary ORDER BY collection_media.id DESC to the collection media pagination query to ensure deterministic ordering across pages
  • Items with the same addDate (common when batch-added by rule handler) could appear on multiple pages or be skipped entirely due to SQLite's non-deterministic row ordering for equal sort values

Closes #2443

Test plan

  • yarn build passes
  • yarn test — all 494 tests pass
  • Verify in a collection with many items that scrolling no longer produces duplicates or missing entries

Adds a secondary ORDER BY on `id` to prevent duplicate and missing items
when paginating collection media. Items sharing the same `addDate` could
appear on multiple pages or be skipped entirely due to SQLite's
non-deterministic row ordering for equal sort values.

Closes #2443
@enoch85 enoch85 requested a review from ydkmlt84 as a code owner March 1, 2026 10:28
…cate fetches

Replace useState loading guards with useRef to prevent stale closure
reads in scroll and fill-page effects, matching the working
CollectionExclusions pattern.
enoch85 added a commit that referenced this pull request Mar 1, 2026
PR #2444 - fix(ui): use ref-based guards in CollectionMediaPage to prevent duplicate fetches
- Replace state-based fetch guards with refs to avoid React batching issues
- Prevent duplicate API calls during pagination and collection media loading
enoch85 added 2 commits March 2, 2026 16:28
… fetches

The stale scroll handler closure in OverviewContent could trigger
fetchData() concurrently with the fill-page effect, causing the same
page to be fetched twice and subsequent pages to be skipped.
enoch85 added a commit that referenced this pull request Mar 2, 2026
PR #2444 - fix(ui): add fetchingRef guard in Overview to prevent concurrent page fetches
- Add ref-based guard to Overview component to prevent concurrent page fetches
- Mirrors the same pattern applied to CollectionMediaPage in previous commit
@enoch85 enoch85 self-assigned this Mar 10, 2026
enoch85 added 2 commits March 24, 2026 19:51
Add a generation counter so that when a library switch invalidates an
in-flight request, the old response cannot reset fetchingRef/loading
state for the new library. Wrap the fetch in try/finally so a failed
request also clears its own guards, preventing a pagination deadlock.
@enoch85 enoch85 merged commit 7ea935a into main Mar 24, 2026
12 checks passed
@enoch85 enoch85 deleted the fix/collection-pagination-duplicates branch March 24, 2026 19:13
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incomplete / Duplicate listings in collection

1 participant