No need to make two filesystem calls when checking version of thumbnail cache

This commit is contained in:
Kovid Goyal 2024-01-25 21:29:17 +05:30
parent 3dcdc766ee
commit 07f988b109
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -10,6 +10,7 @@ import re
import shutil
import sys
from collections import OrderedDict, namedtuple
from contextlib import suppress
from locale import localeconv
from threading import Lock
@ -156,12 +157,8 @@ class ThumbnailCache:
# Remove the cache if it isn't the current version
version_path = os.path.join(self.location, 'version')
current_version = 0
if os.path.exists(version_path):
try:
with open(version_path) as f:
with suppress(Exception), open(version_path) as f:
current_version = int(f.read())
except:
pass
if current_version != self.version:
# The version number changed. Delete the cover cache. Can't delete
# it if it isn't there (first time). Note that this will not work