From 2dbfde29cedf1f4d5f0f3792b02d34a61d752c98 Mon Sep 17 00:00:00 2001 From: Patrick Speiser Date: Sun, 30 Sep 2012 23:09:39 +0200 Subject: [PATCH] Faster checking if something is in the cache --- headphones/cache.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/headphones/cache.py b/headphones/cache.py index 28f9d500..9592e8f3 100644 --- a/headphones/cache.py +++ b/headphones/cache.py @@ -62,21 +62,27 @@ class Cache(object): def __init__(self): pass - - def _exists(self, type): - self.artwork_files = glob.glob(os.path.join(self.path_to_art_cache, self.id + '*')) - self.thumb_files = glob.glob(os.path.join(self.path_to_art_cache, 'T_' + self.id + '*')) + def _findfilesstartingwith(self,pattern,folder): + files = [] + for fname in os.listdir(folder): + if fname.startswith(pattern): + files.append(os.path.join(folder,fname)) + return files + + def _exists(self, type): + self.artwork_files = [] + self.thumb_files = [] if type == 'artwork': - + self.artwork_files = self._findfilesstartingwith(self.id,self.path_to_art_cache) if self.artwork_files: return True else: return False - + elif type == 'thumb': - + self.thumb_files = self._findfilesstartingwith("T_" + self.id,self.path_to_art_cache) if self.thumb_files: return True else: