mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Add has_id() to db.data in the new backend
Also speed up has_id() and all_book_ids()
This commit is contained in:
parent
f8ad733e25
commit
49c82ededa
@ -401,7 +401,7 @@ class Cache(object):
|
|||||||
'''
|
'''
|
||||||
Frozen set of all known book ids.
|
Frozen set of all known book ids.
|
||||||
'''
|
'''
|
||||||
return type(self.fields['uuid'])
|
return type(self.fields['uuid'].table.book_col_map)
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def all_field_ids(self, name):
|
def all_field_ids(self, name):
|
||||||
@ -1236,6 +1236,10 @@ class Cache(object):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@read_api
|
||||||
|
def has_id(self, book_id):
|
||||||
|
return book_id in self.fields['title'].table.book_col_map
|
||||||
|
|
||||||
@write_api
|
@write_api
|
||||||
def create_book_entry(self, mi, cover=None, add_duplicates=True, force_id=None, apply_import_tags=True, preserve_uuid=False):
|
def create_book_entry(self, mi, cover=None, add_duplicates=True, force_id=None, apply_import_tags=True, preserve_uuid=False):
|
||||||
if mi.tags:
|
if mi.tags:
|
||||||
|
@ -143,7 +143,7 @@ class LibraryDatabase(object):
|
|||||||
self.data.cache.initialize_template_cache()
|
self.data.cache.initialize_template_cache()
|
||||||
|
|
||||||
def all_ids(self):
|
def all_ids(self):
|
||||||
for book_id in self.data.cache.all_book_ids():
|
for book_id in self.new_api.all_book_ids():
|
||||||
yield book_id
|
yield book_id
|
||||||
|
|
||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
@ -510,7 +510,7 @@ class LibraryDatabase(object):
|
|||||||
self.new_api._remove_items('tags', tag_ids)
|
self.new_api._remove_items('tags', tag_ids)
|
||||||
|
|
||||||
def has_id(self, book_id):
|
def has_id(self, book_id):
|
||||||
return book_id in self.new_api.all_book_ids()
|
return self.new_api.has_id(book_id)
|
||||||
|
|
||||||
def format(self, index, fmt, index_is_id=False, as_file=False, mode='r+b', as_path=False, preserve_filename=False):
|
def format(self, index, fmt, index_is_id=False, as_file=False, mode='r+b', as_path=False, preserve_filename=False):
|
||||||
book_id = index if index_is_id else self.id(index)
|
book_id = index if index_is_id else self.id(index)
|
||||||
|
@ -135,10 +135,13 @@ class View(object):
|
|||||||
return self.cache.field_metadata
|
return self.cache.field_metadata
|
||||||
|
|
||||||
def _get_id(self, idx, index_is_id=True):
|
def _get_id(self, idx, index_is_id=True):
|
||||||
if index_is_id and idx not in self.cache.all_book_ids():
|
if index_is_id and not self.cache.has_id(idx):
|
||||||
raise IndexError('No book with id %s present'%idx)
|
raise IndexError('No book with id %s present'%idx)
|
||||||
return idx if index_is_id else self.index_to_id(idx)
|
return idx if index_is_id else self.index_to_id(idx)
|
||||||
|
|
||||||
|
def has_id(self, book_id):
|
||||||
|
return self.cache.has_id(book_id)
|
||||||
|
|
||||||
def __getitem__(self, row):
|
def __getitem__(self, row):
|
||||||
return TableRow(self._map_filtered[row], self)
|
return TableRow(self._map_filtered[row], self)
|
||||||
|
|
||||||
@ -177,7 +180,7 @@ class View(object):
|
|||||||
|
|
||||||
def _get(self, field, idx, index_is_id=True, default_value=None, fmt=lambda x:x):
|
def _get(self, field, idx, index_is_id=True, default_value=None, fmt=lambda x:x):
|
||||||
id_ = idx if index_is_id else self.index_to_id(idx)
|
id_ = idx if index_is_id else self.index_to_id(idx)
|
||||||
if index_is_id and id_ not in self.cache.all_book_ids():
|
if index_is_id and not self.cache.has_id(id_):
|
||||||
raise IndexError('No book with id %s present'%idx)
|
raise IndexError('No book with id %s present'%idx)
|
||||||
return fmt(self.cache.field_for(field, id_, default_value=default_value))
|
return fmt(self.cache.field_for(field, id_, default_value=default_value))
|
||||||
|
|
||||||
@ -323,7 +326,7 @@ class View(object):
|
|||||||
self.cache.clear_search_caches(old_marked_ids | set(self.marked_ids))
|
self.cache.clear_search_caches(old_marked_ids | set(self.marked_ids))
|
||||||
|
|
||||||
def refresh(self, field=None, ascending=True, clear_caches=True):
|
def refresh(self, field=None, ascending=True, clear_caches=True):
|
||||||
self._map = tuple(self.cache.all_book_ids())
|
self._map = tuple(sorted(self.cache.all_book_ids()))
|
||||||
self._map_filtered = tuple(self._map)
|
self._map_filtered = tuple(self._map)
|
||||||
if clear_caches:
|
if clear_caches:
|
||||||
self.cache.clear_caches()
|
self.cache.clear_caches()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user