[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) <qsm@odoo.com>
This commit is contained in:
David Ramia
2023-01-10 13:39:51 +01:00
parent 06b6a52648
commit bcf253063f
+7 -3
View File
@@ -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: