Hold the VLs cache lock when checking if the cache exists

This commit is contained in:
Kovid Goyal 2021-05-06 07:26:02 +05:30
parent e9ee3e0546
commit 5ff45a7ee7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2231,13 +2231,13 @@ class Cache(object):
@read_api @read_api
def virtual_libraries_for_books(self, book_ids, virtual_fields=None): def virtual_libraries_for_books(self, book_ids, virtual_fields=None):
if self.vls_for_books_cache is None: # use a primitive lock to ensure that only one thread is updating
# Using a list is slightly faster than a set. # the cache and that recursive calls don't do the update. This
c = defaultdict(list) # method can recurse via self._search()
# use a primitive lock to ensure that only one thread is updating with try_lock(self.vls_cache_lock) as got_lock:
# the cache and that recursive calls don't do the update. This if self.vls_for_books_cache is None:
# method can recurse via self._search() # Using a list is slightly faster than a set.
with try_lock(self.vls_cache_lock) as got_lock: c = defaultdict(list)
if not got_lock: if not got_lock:
# We get here if resolving the books in a VL triggers another VL # We get here if resolving the books in a VL triggers another VL
# calculation. This can be 'real' recursion, in which case the # calculation. This can be 'real' recursion, in which case the