Fix bug in cover cache that could cause it to keep a large number of covers in memory. Showed up when adding large numbers of books to calibre. Fixes #7813 (errors found in terminal after latest stable Calibre closed)

This commit is contained in:
Kovid Goyal 2010-12-08 10:09:52 -07:00
parent bb14142bec
commit e126ddc518

View File

@ -129,6 +129,7 @@ class CoverCache(Thread): # {{{
self.keep_running = True
self.cache = {}
self.lock = RLock()
self.allowed_ids = frozenset([])
self.null_image = QImage()
def stop(self):
@ -175,6 +176,9 @@ class CoverCache(Thread): # {{{
break
for id_ in ids:
time.sleep(0.050) # Limit 20/second to not overwhelm the GUI
with self.lock:
if id_ not in self.allowed_ids:
continue
try:
img = self._image_for_id(id_)
except:
@ -193,6 +197,7 @@ class CoverCache(Thread): # {{{
def set_cache(self, ids):
with self.lock:
self.allowed_ids = frozenset(ids)
already_loaded = set([])
for id in self.cache.keys():
if id in ids: