Skip to content

Commit 66473d6

Browse files
committed
[IMP] util/pg: cache column_exists for common columns
In many cases we know that columns must exist, it's better to cache them to avoid thousands of small queries.
1 parent daa5888 commit 66473d6

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/util/pg.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
from .exceptions import MigrationError, SleepyDeveloperError
4545
from .helpers import _validate_table, model_of_table
46-
from .misc import Sentinel, log_progress
46+
from .misc import Sentinel, log_progress, version_gte
4747

4848
_logger = logging.getLogger(__name__)
4949

@@ -472,6 +472,54 @@ def _column_info(cr, table, column):
472472
return cr.fetchone()
473473

474474

475+
_COLUMNS = {}
476+
if version_gte("10.0"): # Since at least 9.0
477+
_COLUMNS[("ir_model_fields", "depends")] = True
478+
_COLUMNS[("ir_model_fields", "domain")] = True
479+
_COLUMNS[("ir_model_fields", "relation_table")] = True
480+
481+
_COLUMNS[("ir_ui_view", "arch_db")] = True
482+
_COLUMNS[("ir_ui_view", "active")] = True
483+
484+
_COLUMNS[("ir_filters", "sort")] = True
485+
_COLUMNS[("ir_filters", "domain")] = True
486+
_COLUMNS[("ir_filters", "model_id")] = True
487+
488+
_COLUMNS[("ir_model_rule", "domain_force")] = True
489+
490+
_COLUMNS[("ir_model_data", "res_id")] = True
491+
_COLUMNS[("ir_model_data", "model")] = True
492+
_COLUMNS[("ir_model_data", "name")] = True
493+
494+
_COLUMNS[("ir_attachment", "res_field")] = True
495+
_COLUMNS[("ir_attachment", "res_model")] = True
496+
_COLUMNS[("ir_attachment", "res_id")] = True
497+
498+
_COLUMNS[("ir_ui_menu", "action")] = True
499+
500+
_COLUMNS[("ir_act_window", "res_model")] = True
501+
_COLUMNS[("ir_act_window", "res_id")] = True
502+
_COLUMNS[("ir_act_window", "domain")] = True
503+
504+
_COLUMNS[("ir_value", "res_id")] = True
505+
506+
if version_gte("14.0"): # Since at least 13.0
507+
_COLUMNS[("ir_module_module_dependency", "auto_install_required")] = True
508+
_COLUMNS[("ir_act_window", "src_model")] = False
509+
510+
if version_gte("saas~16.1"): # Since 16.0
511+
_COLUMNS[("ir_translation", "name")] = False
512+
513+
if version_gte("saas~17.1"): # Since 17.0
514+
_COLUMNS[("ir_cron", "resource_ref")] = True
515+
_COLUMNS[("ir_act_server", "resource_ref")] = True
516+
517+
if version_gte("saas~18.1"): # Since 18.0
518+
_COLUMNS[("ir_model_fields", "company_dependent")] = True
519+
_COLUMNS[("ir_filters", "embedded_parent_res_id")] = True
520+
_COLUMNS[("ir_act_report_xml", "domain")] = True
521+
522+
475523
def column_exists(cr, table, column):
476524
"""
477525
Return whether a column exists.
@@ -480,7 +528,7 @@ def column_exists(cr, table, column):
480528
:param str column: column to check
481529
:rtype: bool
482530
"""
483-
return _column_info(cr, table, column) is not None
531+
return _COLUMNS[(table, column)] if (table, column) in _COLUMNS else (_column_info(cr, table, column) is not None)
484532

485533

486534
def column_type(cr, table, column):

0 commit comments

Comments
 (0)