Small change to commit d84b1e2 to be a little safer.

This commit is contained in:
Charles Haley 2024-03-17 10:20:19 +00:00
parent d84b1e2009
commit cfc14e774f

View File

@ -972,6 +972,7 @@ class GridView(QListView):
cache_valid = None cache_valid = None
else: else:
# A cover is in the cache. Check whether it is up to date. # A cover is in the cache. Check whether it is up to date.
# Note that if tcdata is not None then it is already a PIL image.
has_cover, tcdata, timestamp = db.new_api.cover_or_cache(book_id, timestamp, has_cover, tcdata, timestamp = db.new_api.cover_or_cache(book_id, timestamp,
as_what='pil_image') as_what='pil_image')
if has_cover: if has_cover:
@ -1012,12 +1013,6 @@ class GridView(QListView):
if cover_tuple.has_cover: if cover_tuple.has_cover:
# cdata contains either the resized thumbnail, the full cover.jpg # cdata contains either the resized thumbnail, the full cover.jpg
# rendered as a PIL image, or None if cover.jpg isn't valid # rendered as a PIL image, or None if cover.jpg isn't valid
if cdata.getbbox() is None and cover_tuple.cache_valid:
# Something wrong with the cover data in the cache. Remove it
# from the cache and queue it to render again.
tc.invalidate((book_id,))
self.render_queue.put(book_id)
return None
if not cover_tuple.cache_valid: if not cover_tuple.cache_valid:
# The cover isn't in the cache, is stale, or isn't a valid # The cover isn't in the cache, is stale, or isn't a valid
# image. We might have the image from cover.jpg, in which case # image. We might have the image from cover.jpg, in which case
@ -1052,6 +1047,20 @@ class GridView(QListView):
# The cover data isn't valid. Remove it from the cache # The cover data isn't valid. Remove it from the cache
tc.invalidate((book_id,)) tc.invalidate((book_id,))
else: else:
# Test to see if there is something wrong with the cover data in
# the cache. If so, remove it from the cache and queue it to
# render again. It isn't clear that this can ever happen. One
# possibility is if different versions of calibre are used
# interchangeably.
def getbbox(img):
try:
return img.getbbox()
except Exception:
return None
if getbbox(cdata) is None:
tc.invalidate((book_id,))
self.render_queue.put(book_id)
return None
# The data from the cover cache is valid and is already a thumb. # The data from the cover cache is valid and is already a thumb.
thumb = cdata thumb = cdata
else: else: