mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
Fixes #1918428 [Match books infinite loop and then crash calibre](https://bugs.launchpad.net/calibre/+bug/1918428)
This commit is contained in:
commit
b7fba0b40e
@ -141,6 +141,7 @@ class Cache(object):
|
|||||||
self.format_metadata_cache = defaultdict(dict)
|
self.format_metadata_cache = defaultdict(dict)
|
||||||
self.formatter_template_cache = {}
|
self.formatter_template_cache = {}
|
||||||
self.dirtied_cache = {}
|
self.dirtied_cache = {}
|
||||||
|
self.vls_for_books_cache = None
|
||||||
self.dirtied_sequence = 0
|
self.dirtied_sequence = 0
|
||||||
self.cover_caches = set()
|
self.cover_caches = set()
|
||||||
self.clear_search_cache_count = 0
|
self.clear_search_cache_count = 0
|
||||||
@ -249,6 +250,7 @@ class Cache(object):
|
|||||||
def clear_search_caches(self, book_ids=None):
|
def clear_search_caches(self, book_ids=None):
|
||||||
self.clear_search_cache_count += 1
|
self.clear_search_cache_count += 1
|
||||||
self._search_api.update_or_clear(self, book_ids)
|
self._search_api.update_or_clear(self, book_ids)
|
||||||
|
self.vls_for_books_cache = None
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def last_modified(self):
|
def last_modified(self):
|
||||||
@ -2207,14 +2209,22 @@ class Cache(object):
|
|||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def virtual_libraries_for_books(self, book_ids):
|
def virtual_libraries_for_books(self, book_ids):
|
||||||
libraries = self._pref('virtual_libraries', {})
|
if self.vls_for_books_cache is None:
|
||||||
ans = {book_id:[] for book_id in book_ids}
|
# Using a list is slightly faster than a set.
|
||||||
for lib, expr in iteritems(libraries):
|
c = defaultdict(list)
|
||||||
books = self._search(expr) # We deliberately dont use book_ids as we want to use the search cache
|
libraries = self._pref('virtual_libraries', {})
|
||||||
for book in book_ids:
|
for lib, expr in libraries.items():
|
||||||
if book in books:
|
for book in self._search(expr):
|
||||||
ans[book].append(lib)
|
c[book].append(lib)
|
||||||
return {k:tuple(sorted(v, key=sort_key)) for k, v in iteritems(ans)}
|
self.vls_for_books_cache = {b:tuple(sorted(libs, key=sort_key)) for b, libs in c.items()}
|
||||||
|
if not book_ids:
|
||||||
|
book_ids = self._all_book_ids()
|
||||||
|
# book_ids is usually 1 long. The loop will be faster than a comprehension
|
||||||
|
r = {}
|
||||||
|
default = ()
|
||||||
|
for b in book_ids:
|
||||||
|
r[b] = self.vls_for_books_cache.get(b, default)
|
||||||
|
return r
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def user_categories_for_books(self, book_ids, proxy_metadata_map=None):
|
def user_categories_for_books(self, book_ids, proxy_metadata_map=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user