1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 18:47:23 +00:00

Reload database on every call to v1/library/sync. This fixes an issue where side-loaded books appear in the sync response with no download urls.

This commit is contained in:
Michael Shavit 2019-12-22 12:58:03 -05:00
parent cdcb8a50d1
commit c238367b64
3 changed files with 10 additions and 3 deletions

View File

@ -429,3 +429,8 @@ def dispose():
if name.startswith("custom_column_") or name.startswith("books_custom_column_"): if name.startswith("custom_column_") or name.startswith("books_custom_column_"):
if table is not None: if table is not None:
Base.metadata.remove(table) Base.metadata.remove(table)
def reconnect_db(config):
session.close()
engine.dispose()
setup_db(config)

View File

@ -227,6 +227,10 @@ def HandleSyncRequest():
new_books_last_created = sync_token.books_last_created new_books_last_created = sync_token.books_last_created
entitlements = [] entitlements = []
# We reload the book database so that the user get's a fresh view of the library
# in case of external changes (e.g: adding a book through Calibre).
db.reconnect_db(config)
# sqlite gives unexpected results when performing the last_modified comparison without the datetime cast. # sqlite gives unexpected results when performing the last_modified comparison without the datetime cast.
# It looks like it's treating the db.Books.last_modified field as a string and may fail # It looks like it's treating the db.Books.last_modified field as a string and may fail
# the comparison because of the +00:00 suffix. # the comparison because of the +00:00 suffix.

View File

@ -784,9 +784,7 @@ def get_tasks_status():
@app.route("/reconnect") @app.route("/reconnect")
def reconnect(): def reconnect():
db.session.close() db.reconnect_db(config)
db.engine.dispose()
db.setup_db(config)
return json.dumps({}) return json.dumps({})
@web.route("/search", methods=["GET"]) @web.route("/search", methods=["GET"])