Commit 24bbf226 authored by alfred82santa's avatar alfred82santa

Sync reading state only for books on kobo shelves

parent 6014b04b
...@@ -171,7 +171,7 @@ def HandleSyncRequest(): ...@@ -171,7 +171,7 @@ def HandleSyncRequest():
ub.BookShelf.date_added > sync_token.books_last_modified)) ub.BookShelf.date_added > sync_token.books_last_modified))
.filter(db.Data.format.in_(KOBO_FORMATS)) .filter(db.Data.format.in_(KOBO_FORMATS))
.order_by(db.Books.id) .order_by(db.Books.id)
.order_by('last_modified') .order_by(ub.ArchivedBook.last_modified)
.join(ub.BookShelf, db.Books.id == ub.BookShelf.book_id) .join(ub.BookShelf, db.Books.id == ub.BookShelf.book_id)
.join(ub.Shelf) .join(ub.Shelf)
.filter(ub.Shelf.kobo_sync) .filter(ub.Shelf.kobo_sync)
...@@ -253,11 +253,36 @@ def HandleSyncRequest(): ...@@ -253,11 +253,36 @@ def HandleSyncRequest():
books_last_id = -1 books_last_id = -1
# generate reading state data # generate reading state data
changed_reading_states = ub.session.query(ub.KoboReadingState)
if only_kobo_shelves:
changed_reading_states = (
changed_reading_states.join(ub.BookShelf, ub.KoboReadingState.book_id == ub.BookShelf.book_id)
.join(ub.Shelf)
.filter(
ub.Shelf.kobo_sync,
or_(
func.datetime(ub.KoboReadingState.last_modified) > sync_token.reading_state_last_modified,
ub.BookShelf.date_added > sync_token.books_last_modified
)
)
).distinct()
else:
changed_reading_states = (
changed_reading_states.filter(
func.datetime(ub.KoboReadingState.last_modified) > sync_token.reading_state_last_modified
)
)
changed_reading_states = ( changed_reading_states = (
ub.session.query(ub.KoboReadingState) changed_reading_states.filter(
.filter(and_(func.datetime(ub.KoboReadingState.last_modified) > sync_token.reading_state_last_modified, and_(
ub.KoboReadingState.user_id == current_user.id, ub.KoboReadingState.user_id == current_user.id,
ub.KoboReadingState.book_id.notin_(reading_states_in_new_entitlements)))) ub.KoboReadingState.book_id.notin_(reading_states_in_new_entitlements)
)
)
)
for kobo_reading_state in changed_reading_states.all(): for kobo_reading_state in changed_reading_states.all():
book = calibre_db.session.query(db.Books).filter(db.Books.id == kobo_reading_state.book_id).one_or_none() book = calibre_db.session.query(db.Books).filter(db.Books.id == kobo_reading_state.book_id).one_or_none()
if book: if book:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment