Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] BS4->BS5: performance #370

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .openupgrade_tools import (
convert_html_fragment,
convert_html_replacement_class_shortcut as _r,
not_html_empty_where_clause,
replace_html_replacement_attr_shortcut as _attr_replace,
replace_html_replacement_class_rp_by_inline_shortcut as _class_rp_by_inline,
)
Expand Down Expand Up @@ -344,10 +345,9 @@ def convert_field_bootstrap_4to5(
field_name,
domain,
)
records = env[model_name].search(domain or [])
return _convert_field_bootstrap_4to5_sql(
env.cr,
records._table,
env[model_name]._table,
field_name,
)

Expand All @@ -360,8 +360,10 @@ def _convert_field_bootstrap_4to5_orm(env, model_name, field_name, domain=None):
:param str field_name: Field to convert in that model.
:param domain list: Domain to restrict conversion.
"""
domain = domain or [(field_name, "!=", False), (field_name, "!=", "<p><br></p>")]
records = env[model_name].search(domain)
domain = domain or []
query = env[model_name]._search(domain)
query.add_where(not_html_empty_where_clause(field_name))
records = env[model_name].browse(query)
update_field_multilang(
records,
field_name,
Expand Down
24 changes: 24 additions & 0 deletions openupgradelib/openupgrade_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,27 @@ def invalidate_cache(env, flush=True):
env.invalidate_all()
else:
raise Exception("Not supported Odoo version for this method.")


def not_html_empty_where_clause(column):
"""Add this where clause to your query to optimize when to deal with an html record
value or not. Follows the same rules as odoo.tools.is_html_empty

:param string column:

:return string:
The where clause for the html column ready to select only values with content.
"""
return f"""
NOT (
{column} IS NULL
OR {column} = ''
OR NOT (
regexp_replace(
{column},
'\\<\\s*\\/?(?:p|div|span|br|b|i|font)(?:(?=\\s+\\w*)[^/>]*|\\s*)/?\\s*\\>',
'',
'g'
) ~ '\\S'
)
)"""
Loading