From 6f9e52792ac66f129833afc102ece8f16d87d181 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 10 Jan 2021 11:01:54 +0100 Subject: [PATCH] No autoflush on metadata.db change --- cps/db.py | 16 +++++++++++----- cps/gdriveutils.py | 3 ++- cps/tasks/convert.py | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cps/db.py b/cps/db.py index f30fb609..dbb90ff1 100644 --- a/cps/db.py +++ b/cps/db.py @@ -402,7 +402,10 @@ class AlchemyEncoder(json.JSONEncoder): el.append(ele.get()) else: el.append(json.dumps(ele, cls=AlchemyEncoder)) - data = ",".join(el) + if field == 'authors': + data = " & ".join(el) + else: + data = ",".join(el) if data == '[]': data = "" else: @@ -542,7 +545,7 @@ class CalibreDB(): backref='books')) cls.session_factory = scoped_session(sessionmaker(autocommit=False, - autoflush=True, + autoflush=False, bind=cls.engine)) for inst in cls.instances: inst.initSession() @@ -619,9 +622,12 @@ class CalibreDB(): .join(*join, isouter=True) \ .filter(db_filter) \ .filter(self.common_filters(allow_show_archived)) - pagination = Pagination(page, pagesize, - len(query.all())) - entries = query.order_by(*order).offset(off).limit(pagesize).all() + try: + pagination = Pagination(page, pagesize, + len(query.all())) + entries = query.order_by(*order).offset(off).limit(pagesize).all() + except Exception as e: + logger.debug(e) for book in entries: book = self.order_authors(book) return entries, randm, pagination diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 6f78ab47..79587b79 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -394,7 +394,8 @@ def uploadFileToEbooksFolder(destFile, f): if len(existingFiles) > 0: driveFile = existingFiles[0] else: - driveFile = drive.CreateFile({'title': x, 'parents': [{"kind": "drive#fileLink", 'id': parent['id']}],}) + driveFile = drive.CreateFile({'title': x, + 'parents': [{"kind": "drive#fileLink", 'id': parent['id']}], }) driveFile.SetContentFile(f) driveFile.Upload() else: diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index d3e74569..93f964f9 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -123,6 +123,7 @@ class TaskConvert(CalibreTask): book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext)) try: local_db.session.merge(new_format) + local_db.session.flush() local_db.session.commit() except SQLAlchemyError as e: local_db.session.rollback()