From dc88a74caab4b02a9e18636fb09306dc6902ce9d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 May 2021 15:18:11 +0530 Subject: [PATCH] Oops, forgot to move test for lock failure above cache access --- src/calibre/db/cache.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 1c0f9c1b69..f244c3405b 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -2235,18 +2235,18 @@ class Cache(object): # the cache and that recursive calls don't do the update. This # method can recurse via self._search() with try_lock(self.vls_cache_lock) as got_lock: + # Using a list is slightly faster than a set. + c = defaultdict(list) + if not got_lock: + # We get here if resolving the books in a VL triggers another VL + # calculation. This can be 'real' recursion, in which case the + # eventual answer will be wrong. It can also be a search using + # a location of 'all' that causes evaluation of a composite that + # references virtual_libraries(). If the composite isn't used in a + # VL then the eventual answer will be correct because get_metadata + # will clear the caches. + return c if self.vls_for_books_cache is None: - # Using a list is slightly faster than a set. - c = defaultdict(list) - if not got_lock: - # We get here if resolving the books in a VL triggers another VL - # calculation. This can be 'real' recursion, in which case the - # eventual answer will be wrong. It can also be a search using - # a location of 'all' that causes evaluation of a composite that - # references virtual_libraries(). If the composite isn't used in a - # VL then the eventual answer will be correct because get_metadata - # will clear the caches. - return c self.vls_for_books_cache_is_loading = True libraries = self._pref('virtual_libraries', {}) for lib, expr in libraries.items():