Avoid re-processing a block that is already in the manifest when compressing offline
This commit is contained in:
@@ -220,6 +220,10 @@ class Command(NoArgsCommand):
|
||||
parser.process_node(template, context, node)
|
||||
rendered = parser.render_nodelist(template, context, node)
|
||||
key = get_offline_hexdigest(rendered)
|
||||
|
||||
if key in offline_manifest:
|
||||
continue
|
||||
|
||||
try:
|
||||
result = parser.render_node(template, context, node)
|
||||
except Exception as e:
|
||||
|
@@ -137,6 +137,25 @@ class OfflineTestCaseMixin(object):
|
||||
return loader
|
||||
|
||||
|
||||
class OfflineGenerationSkipDuplicatesTestCase(OfflineTestCaseMixin, TestCase):
|
||||
templates_dir = "test_duplicate"
|
||||
|
||||
# We don't need to test multiples engines here.
|
||||
engines = ("django",)
|
||||
|
||||
def _test_offline(self, engine):
|
||||
count, result = CompressCommand().compress(log=self.log, verbosity=self.verbosity, engine=engine)
|
||||
# Only one block compressed, the second identical one was skipped.
|
||||
self.assertEqual(1, count)
|
||||
# Only 1 <script> block in returned result as well.
|
||||
self.assertEqual([
|
||||
'<script type="text/javascript" src="/static/CACHE/js/f5e179b8eca4.js"></script>',
|
||||
], result)
|
||||
rendered_template = self._render_template(engine)
|
||||
# But rendering the template returns both (identical) scripts.
|
||||
self.assertEqual(rendered_template, "".join(result * 2) + "\n")
|
||||
|
||||
|
||||
class OfflineGenerationBlockSuperTestCase(OfflineTestCaseMixin, TestCase):
|
||||
templates_dir = "test_block_super"
|
||||
expected_hash = "7c02d201f69d"
|
||||
|
@@ -0,0 +1,13 @@
|
||||
{% load compress %}{% spaceless %}
|
||||
|
||||
{% compress js %}
|
||||
<script type="text/javascript">
|
||||
alert("Basic test");
|
||||
</script>
|
||||
{% endcompress %}
|
||||
{% compress js %}
|
||||
<script type="text/javascript">
|
||||
alert("Basic test");
|
||||
</script>
|
||||
{% endcompress %}
|
||||
{% endspaceless %}
|
Reference in New Issue
Block a user