Skip to content

Commit

Permalink
Set the post process cache when finished instead of one by one.
Browse files Browse the repository at this point in the history
This should prevent a race condition if running collectstatic is
canceled or its cache is accessed from other processes, leaving the
cache in a corrupt state.
  • Loading branch information
jezdez committed May 10, 2012
1 parent c2e1ecb commit 1c1a229
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions django/contrib/staticfiles/storage.py
Expand Up @@ -189,8 +189,8 @@ def post_process(self, paths, dry_run=False, **options):
if dry_run:
return

# delete cache of all handled paths
self.cache.delete_many([self.cache_key(path) for path in paths])
# where to store the new paths
hashed_paths = {}

# build a list of adjustable files
matches = lambda path: matches_patterns(path, self._patterns.keys())
Expand Down Expand Up @@ -239,9 +239,12 @@ def post_process(self, paths, dry_run=False, **options):
hashed_name = force_unicode(saved_name.replace('\\', '/'))

# and then set the cache accordingly
self.cache.set(self.cache_key(name), hashed_name)
hashed_paths[self.cache_key(name)] = hashed_name
yield name, hashed_name, processed

# Finally set the cache
self.cache.set_many(hashed_paths)


class CachedStaticFilesStorage(CachedFilesMixin, StaticFilesStorage):
"""
Expand Down

1 comment on commit 1c1a229

@cyberdelia
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟

Please sign in to comment.