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