Fetch the manifest file only once and store the results in a module level variable.

This commit is contained in:
Jaap Roes
2012-02-15 20:33:15 +01:00
parent 835ed4ef70
commit 5e27d6b4b4
2 changed files with 18 additions and 5 deletions

View File

@@ -62,18 +62,29 @@ def get_offline_manifest_filename():
return os.path.join(output_dir, settings.COMPRESS_OFFLINE_MANIFEST)
_offline_manifest = None
def get_offline_manifest():
filename = get_offline_manifest_filename()
if default_storage.exists(filename):
return simplejson.load(default_storage.open(filename))
else:
return {}
global _offline_manifest
if _offline_manifest is None:
filename = get_offline_manifest_filename()
if default_storage.exists(filename):
_offline_manifest = simplejson.load(default_storage.open(filename))
else:
_offline_manifest = {}
return _offline_manifest
def flush_offline_manifest():
global _offline_manifest
_offline_manifest = None
def write_offline_manifest(manifest):
filename = get_offline_manifest_filename()
default_storage.save(filename,
ContentFile(simplejson.dumps(manifest, indent=2)))
flush_offline_manifest()
def get_templatetag_cachekey(compressor, mode, kind):

View File

@@ -9,6 +9,7 @@ except ImportError:
from django.template import Template, Context
from django.test import TestCase
from compressor.cache import flush_offline_manifest
from compressor.conf import settings
from compressor.exceptions import OfflineGenerationError
from compressor.management.commands.compress import Command as CompressCommand
@@ -134,6 +135,7 @@ class OfflineGenerationTestCase(OfflineTestCaseMixin, TestCase):
expected_hash = "f5e179b8eca4"
def test_rendering_without_compressing_raises_exception(self):
flush_offline_manifest()
self.assertRaises(OfflineGenerationError,
self.template.render, Context({}))