From bcf253063f54b65401aaa37a4435249c64962647 Mon Sep 17 00:00:00 2001 From: David Ramia Date: Sun, 8 Jan 2023 16:32:50 +0000 Subject: [PATCH] [FIX] website: optimize the asset disabling function Before this commit, the behavior disabling the unused snippet assets performed two checks: 1. It was looking for occurrences for its use in the snippet template 2. It was looking for occurrences for its use in the HTML fields 3. Checked on the occurrences of step 1 and 2 and return result. In many cases there are already coincidences in the first step, making the second step unnecessary since this second one is the slowest. Matches are now checked between steps 1 and 2 to skip the second if matches are already found. closes odoo/odoo#109488 X-original-commit: 56100532dbcbdeb5487662d0cbf35ba6d62b15b5 Signed-off-by: Quentin Smetz (qsm) --- addons/website/models/website.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 1e95c7ac37a..d7c95485282 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1389,6 +1389,9 @@ class Website(models.Model): match = re.search('<([^>]*class="[^>]*)>', snippet_template_html) snippet_occurences.append(match.group()) + if self._check_snippet_used(snippet_occurences, asset_type, asset_version): + return True + # As well as every snippet dropped in html fields self.env.cr.execute(sql.SQL(" UNION ").join( sql.SQL("SELECT regexp_matches({}{}, {}, 'g') FROM {}").format( @@ -1398,10 +1401,11 @@ class Website(models.Model): sql.Identifier(table) ) for _model, table, column, translate in html_fields_attributes ), {'snippet_regex': f'<([^>]*data-snippet="{snippet_id}"[^>]*)>'}) - results = self.env.cr.fetchall() - for r in results: - snippet_occurences.append(r[0][0]) + snippet_occurences = [r[0][0] for r in self.env.cr.fetchall()] + return self._check_snippet_used(snippet_occurences, asset_type, asset_version) + + def _check_snippet_used(self, snippet_occurences, asset_type, asset_version): for snippet in snippet_occurences: if asset_version == '000': if f'data-v{asset_type}' not in snippet: