Commit 334e3dd2 by Timothée Peignier

improve and cache version_from_file calculations

parent 2aaf293f
from django.dispatch import Signal
import os
from django.core.cache import cache
from django.dispatch import Signal, receiver
css_compressed = Signal(providing_args=["package", "version"])
js_compressed = Signal(providing_args=["package", "version"])
@receiver(css_compressed)
@receiver(js_compressed)
def invalidate_cache(sender, package, version, **kwargs):
filename_base, filename = os.path.split(package['output'])
cache.set("pipeline:%s" % filename, str(version))
import os
import re
from django.core.cache import cache
from pipeline.conf import settings
from pipeline.storage import storage
from pipeline.utils import to_class
......@@ -18,15 +20,18 @@ class Versioning(object):
return getattr(self.versioner, 'version')(paths)
def version_from_file(self, path, filename):
filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)])
version = cache.get("pipeline:%s" % filename)
if not version:
filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part)
for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)])
regex = re.compile(r'^%s$' % self.output_filename(filename, r'([A-Za-z0-9]+)'))
versions = []
for f in sorted(storage.listdir(path)[1], reverse=True):
version = regex.match(f)
if version and version.groups():
versions.append(version.group(1))
versions.sort()
return versions[-1]
for f in storage.listdir(path)[1]:
match = regex.match(f)
if match and match.groups():
version = match.group(1)
break
cache.set("pipeline:%s" % filename, version)
return str(version)
def output_filename(self, filename, version):
if settings.PIPELINE_VERSION and version is not None:
......@@ -46,7 +51,8 @@ class Versioning(object):
return # Nothing to delete here
path = os.path.dirname(filename)
filename = os.path.basename(filename)
filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)])
filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part)
for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)])
regex = re.compile(r'^%s$' % self.output_filename(filename, r'([A-Za-z0-9]+)'))
try:
for f in storage.listdir(path)[1]:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment