From b94fcefeba6e24df3ceefe45308f8ae683bac724 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 23 Apr 2023 15:22:28 +0100 Subject: [PATCH] Requested changes to extra_files API --- src/calibre/db/backup.py | 2 -- src/calibre/db/cache.py | 31 +++---------------------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/src/calibre/db/backup.py b/src/calibre/db/backup.py index 246cfb431a..2437d7169d 100644 --- a/src/calibre/db/backup.py +++ b/src/calibre/db/backup.py @@ -69,8 +69,6 @@ class MetadataBackup(Thread): return traceback.print_exc() - self.db.save_extra_files_cache() - try: book_id = self.db.get_a_dirtied_book() if book_id is None: diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index d32be529f1..f90b653e2b 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -253,8 +253,6 @@ class Cache: if self.dirtied_cache: self.dirtied_sequence = max(itervalues(self.dirtied_cache))+1 self._initialize_dynamic_categories() - self.extra_files_cache = self.backend.prefs.get('extra_files_cache', {}) - self.extra_files_cache_dirty = False @write_api def initialize_template_cache(self): @@ -279,29 +277,9 @@ class Cache: @write_api def clear_extra_files_cache(self, book_id=None): if book_id is None: - pref_changed = bool(self.extra_files_cache) self.extra_files_cache = {} else: - pref_changed = self.extra_files_cache.pop(str(book_id), False) - if pref_changed: - # self.backend.prefs.set('extra_files_cache', self.extra_files_cache) - self.extra_files_cache_dirty = True - - @write_api - def add_to_extra_files_cache(self, book_id, data): - self.extra_files_cache[str(book_id)] = data - # self.backend.prefs.set('extra_files_cache', self.extra_files_cache) - self.extra_files_cache_dirty = True - - @write_api - def save_extra_files_cache(self): - if self.extra_files_cache_dirty: - self.backend.prefs.set('extra_files_cache', self.extra_files_cache) - self.extra_files_cache_dirty = False - - @read_api - def get_extra_files_from_cache(self, book_id): - return self.extra_files_cache.get(str(book_id), {}) + self.extra_files_cache.pop(book_id, None) @read_api def last_modified(self): @@ -2694,8 +2672,6 @@ class Cache: plugin.run(self) except Exception: traceback.print_exc() - # do this last in case a plugin changes the extra files - self.save_extra_files_cache() self._shutdown_fts(stage=2) with self.write_lock: self.backend.close() @@ -3133,7 +3109,7 @@ class Cache: fsize is the file's size in bytes ''' - ans = self.get_extra_files_from_cache(book_id) + ans = self.extra_files_cache.get(book_id, {}) if not ans: path = self._field_for('path', book_id) if path: @@ -3142,8 +3118,7 @@ class Cache: book_id, book_path, None, yield_paths=True): ans[file_path] = dict(zip(('relpath', 'mtime', 'fsize'), (relpath, mtime, fsize))) - if ans: - self.add_to_extra_files_cache(book_id, ans) + self.extra_files_cache[book_id] = ans return ans @read_api