mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Move code that deals with the dirtied table into backend
This commit is contained in:
parent
6bda5e6aad
commit
1002a9bcdd
@ -1756,6 +1756,16 @@ class DB(object):
|
||||
else:
|
||||
self.execute('DELETE FROM books_plugin_data WHERE name=?', (name,))
|
||||
|
||||
def dirtied_books(self):
|
||||
for (book_id,) in self.execute('SELECT book FROM metadata_dirtied'):
|
||||
yield book_id
|
||||
|
||||
def dirty_books(self, book_ids):
|
||||
self.executemany('INSERT OR IGNORE INTO metadata_dirtied (book) VALUES (?)', ((x,) for x in book_ids))
|
||||
|
||||
def mark_book_as_clean(self, book_id):
|
||||
self.execute('DELETE FROM metadata_dirtied WHERE book=?', (book_id,))
|
||||
|
||||
def get_ids_for_custom_book_data(self, name):
|
||||
return frozenset(r[0] for r in self.execute('SELECT book FROM books_plugin_data WHERE name=?', (name,)))
|
||||
|
||||
|
@ -212,8 +212,7 @@ class Cache(object):
|
||||
|
||||
@write_api
|
||||
def initialize_dynamic(self):
|
||||
self.dirtied_cache = {x:i for i, (x,) in enumerate(
|
||||
self.backend.execute('SELECT book FROM metadata_dirtied'))}
|
||||
self.dirtied_cache = {x:i for i, x in enumerate(self.backend.dirtied_books())}
|
||||
if self.dirtied_cache:
|
||||
self.dirtied_sequence = max(itervalues(self.dirtied_cache))+1
|
||||
self._initialize_dynamic_categories()
|
||||
@ -1086,17 +1085,15 @@ class Cache(object):
|
||||
self.dirtied_sequence = max(itervalues(already_dirtied)) + 1
|
||||
self.dirtied_cache.update(already_dirtied)
|
||||
if new_dirtied:
|
||||
self.backend.executemany('INSERT OR IGNORE INTO metadata_dirtied (book) VALUES (?)',
|
||||
((x,) for x in new_dirtied))
|
||||
self.backend.dirty_books(new_dirtied)
|
||||
new_dirtied = {book_id:self.dirtied_sequence+i for i, book_id in enumerate(new_dirtied)}
|
||||
self.dirtied_sequence = max(itervalues(new_dirtied)) + 1
|
||||
self.dirtied_cache.update(new_dirtied)
|
||||
|
||||
@write_api
|
||||
def commit_dirty_cache(self):
|
||||
book_ids = [(x,) for x in self.dirtied_cache]
|
||||
if book_ids:
|
||||
self.backend.executemany('INSERT OR IGNORE INTO metadata_dirtied (book) VALUES (?)', book_ids)
|
||||
if self.dirtied_cache:
|
||||
self.backend.dirty_books(self.dirtied_cache)
|
||||
|
||||
@write_api
|
||||
def set_field(self, name, book_id_to_val_map, allow_case_change=True, do_path_update=True):
|
||||
@ -1195,8 +1192,7 @@ class Cache(object):
|
||||
# The last step is clearing the indicator
|
||||
dc_sequence = self.dirtied_cache.get(book_id, None)
|
||||
if dc_sequence is None or sequence is None or dc_sequence == sequence:
|
||||
self.backend.execute('DELETE FROM metadata_dirtied WHERE book=?',
|
||||
(book_id,))
|
||||
self.backend.mark_book_as_clean(book_id)
|
||||
self.dirtied_cache.pop(book_id, None)
|
||||
|
||||
@write_api
|
||||
|
Loading…
x
Reference in New Issue
Block a user