Browse Source

Song errors are cached only if there isn't any of them

pull/176/head
Louis 9 years ago
parent
commit
38f87923d8
  1. 23
      patacrep/songs/__init__.py

23
patacrep/songs/__init__.py

@ -90,7 +90,7 @@ class Song:
# Version format of cached song. Increment this number if we update # Version format of cached song. Increment this number if we update
# information stored in cache. # information stored in cache.
CACHE_VERSION = 3 CACHE_VERSION = 4
# List of attributes to cache # List of attributes to cache
cached_attributes = [ cached_attributes = [
@ -98,6 +98,7 @@ class Song:
"unprefixed_titles", "unprefixed_titles",
"cached", "cached",
"data", "data",
"errors",
"lang", "lang",
"authors", "authors",
"_filehash", "_filehash",
@ -185,13 +186,19 @@ class Song:
def _write_cache(self): def _write_cache(self):
"""If relevant, write a dumbed down version of self to the cache.""" """If relevant, write a dumbed down version of self to the cache."""
if self.use_cache: if not self.use_cache:
cached = {attr: getattr(self, attr) for attr in self.cached_attributes} return
pickle.dump( if self.errors:
cached, # As errors are exceptions, we cannot cache them because of a Python
open(self.cached_name, 'wb'), # bug. When this bug is fixed, we will cache errors.
protocol=-1 # https://bugs.python.org/issue1692335
) return
cached = {attr: getattr(self, attr) for attr in self.cached_attributes}
pickle.dump(
cached,
open(self.cached_name, 'wb'),
protocol=-1
)
def __str__(self): def __str__(self):
return str(self.fullpath) return str(self.fullpath)

Loading…
Cancel
Save