From e037be06a43190193f8e81e304993fce7f081ff1 Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Sun, 18 May 2014 02:49:42 +0200 Subject: [PATCH] Avoid re-processing a block that is already in the manifest when compressing offline --- compressor/management/commands/compress.py | 4 ++++ compressor/tests/test_offline.py | 19 +++++++++++++++++++ .../test_compressor_offline.html | 13 +++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 compressor/tests/test_templates/test_duplicate/test_compressor_offline.html diff --git a/compressor/management/commands/compress.py b/compressor/management/commands/compress.py index f0603cd..6be215e 100644 --- a/compressor/management/commands/compress.py +++ b/compressor/management/commands/compress.py @@ -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: diff --git a/compressor/tests/test_offline.py b/compressor/tests/test_offline.py index 54e8b08..327b901 100644 --- a/compressor/tests/test_offline.py +++ b/compressor/tests/test_offline.py @@ -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 ', + ], 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" diff --git a/compressor/tests/test_templates/test_duplicate/test_compressor_offline.html b/compressor/tests/test_templates/test_duplicate/test_compressor_offline.html new file mode 100644 index 0000000..6050c8b --- /dev/null +++ b/compressor/tests/test_templates/test_duplicate/test_compressor_offline.html @@ -0,0 +1,13 @@ +{% load compress %}{% spaceless %} + +{% compress js %} + +{% endcompress %} +{% compress js %} + +{% endcompress %} +{% endspaceless %}