No autoflush on metadata.db change

This commit is contained in:
Ozzie Isaacs 2021-01-10 11:01:54 +01:00
parent 4a9b01e93b
commit 6f9e52792a
3 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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:

View File

@ -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()