From 160c7c873d2b7de071531bcc6d98f5b77e6c2e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulius=20Sladkevi=C4=8Dius?= Date: Wed, 16 Nov 2022 12:45:40 +0100 Subject: [PATCH] [IMP] bi_sql_editor manual field check performance The `table_columns()` slows down modules loading significantly up to 2-3x. In most cases `model._name.startswith(self._model_prefix)` returns `False`, so better to check it first. --- bi_sql_editor/models/bi_sql_view.py | 6 +++--- bi_sql_editor/models/bi_sql_view_field.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py index 9343815c7..24c029f7f 100644 --- a/bi_sql_editor/models/bi_sql_view.py +++ b/bi_sql_editor/models/bi_sql_view.py @@ -704,9 +704,9 @@ class BiSQLView(models.Model): def check_manual_fields(self, model): # check the fields we need are defined on self, to stop it going # early on install / startup - particularly problematic during upgrade - if "group_operator" in table_columns( - self.env.cr, "bi_sql_view_field" - ) and model._name.startswith(self._model_prefix): + if model._name.startswith( + self._model_prefix + ) and "group_operator" in table_columns(self.env.cr, "bi_sql_view_field"): # Use SQL instead of ORM, as ORM might not be fully initialised - # we have no control over the order that fields are defined! # We are not concerned about user security rules. diff --git a/bi_sql_editor/models/bi_sql_view_field.py b/bi_sql_editor/models/bi_sql_view_field.py index d37e04cc6..039788a90 100644 --- a/bi_sql_editor/models/bi_sql_view_field.py +++ b/bi_sql_editor/models/bi_sql_view_field.py @@ -180,7 +180,7 @@ class BiSQLViewField(models.Model): "many2one_model_id": many2one_model_id, } ) - return super().create(vals) + return super().create(vals_list) # Custom Section @api.model