Ensure that an error in set_metadata does not cause the memory and disk

data to diverge
This commit is contained in:
Kovid Goyal 2013-07-30 11:46:54 +05:30
parent 82d7bd3d57
commit 2fd8022e9e

View File

@ -1094,6 +1094,7 @@ class Cache(object):
if cdata is not None: if cdata is not None:
self._set_cover({book_id: cdata}) self._set_cover({book_id: cdata})
try:
with self.backend.conn: # Speed up set_metadata by not operating in autocommit mode with self.backend.conn: # Speed up set_metadata by not operating in autocommit mode
for field in ('rating', 'series_index', 'timestamp'): for field in ('rating', 'series_index', 'timestamp'):
val = getattr(mi, field) val = getattr(mi, field)
@ -1136,6 +1137,9 @@ class Cache(object):
extra = mi.get_extra(key) extra = mi.get_extra(key)
if extra is not None or force_changes: if extra is not None or force_changes:
protected_set_field(idx, extra) protected_set_field(idx, extra)
except:
self._reload_from_db()
raise
@write_api @write_api
def add_format(self, book_id, fmt, stream_or_path, replace=True, run_hooks=True, dbapi=None): def add_format(self, book_id, fmt, stream_or_path, replace=True, run_hooks=True, dbapi=None):