Skip to content

Fix Kobo Sync Download Loop and Pagination Bugs#3584

Open
leahjessie wants to merge 1 commit intojaneczku:masterfrom
leahjessie:pr/kobo-sync
Open

Fix Kobo Sync Download Loop and Pagination Bugs#3584
leahjessie wants to merge 1 commit intojaneczku:masterfrom
leahjessie:pr/kobo-sync

Conversation

@leahjessie
Copy link
Copy Markdown
Contributor

Fix Kobo Sync Download Loop and Pagination Bugs

Summary

This PR fixes Kobo sync issues that caused repeated downloads, missed re-syncs, and pagination loops.
It builds on PR #3352 and resolves additional cursor, filtering, and continuation bugs.

Key Fixes

  • Sync cursor separation

    • Split tracking into:
      • books_last_modified for content changes
      • tags_last_modified for shelf membership changes (BookShelf.date_added)
    • Prevents conflating “book changed” with “book added to shelf”.
  • Timestamp normalization

    • Normalize Books.last_modified by stripping +00:00 before token comparison.
  • Resync filtering logic

    • Removed incorrect db.Books.id.notin_(KoboSyncedBooks) filter, which blocked legitimate re-syncs when book content changed.
    • Applied correct checks:
      • date_added > tags_last_modified
      • last_modified > books_last_modified
    • Added distinct() for multi-shelf deduplication.
    • Applied equivalent fixes to full-library sync mode.
  • Pagination correctness

    • Replaced cont_sync = bool(book_count) with cont_sync = bool(book_count > SYNC_ITEM_LIMIT).
    • Added books_last_id tiebreaker for identical last_modified timestamps.
    • Composite cursor:
      • last_modified > token.books_last_modified
      • OR same timestamp with id > token.books_last_id
    • Sync token updated to 1-2-0 (backward compatible; missing books_last_id defaults to -1).
  • KEPUB sync reliability

    • Update last_modified after successful KEPUB/EPUB conversion so converted books are picked up.
    • Trigger conversion when EPUB-only books are added to Kobo-synced shelves.

Files Touched

  • cps/kobo.py
  • cps/services/SyncToken.py
  • cps/shelf.py
  • cps/tasks/convert.py

Testing

Targeted integration pytests are available in my fork:

Many of these tests fail on current master; all pass on ref-pr/kobo-sync-tests.

Coverage includes:

  • unchanged-library sync returning empty
  • modified-only re-sync behavior
  • shelf-mode pagination without repeat loops
  • sync limit boundary behavior
  • KEPUB conversion trigger/sync visibility

Local validation: In addition to the pytest coverage above, I've repeatedly run Kobo sync on my local Calibre-Web environment (including shelf-only flows) and observed no repeat-download loop, correct modified-book re-sync, and stable pagination.

Expected Behavior After This PR

  • Unchanged books are not re-downloaded.
  • Modified books are re-synced in both shelf-only and full-library modes.
  • Pagination continues only when more than SYNC_ITEM_LIMIT items remain.
  • Books with identical last_modified timestamps paginate without repeat loops.
  • Newly converted KEPUB books are picked up on the next sync.

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.

1 participant