summaryrefslogtreecommitdiff
path: root/odoo/modules
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2019-10-23 13:32:07 +0000
committerRaphael Collet <rco@odoo.com>2019-10-23 15:12:51 +0000
commit15f3d5a139903c991a6958e92c17d5e4c97fd44b (patch)
tree2aa79067685a7efcbba884df09987c8fd611d325 /odoo/modules
parentd6c54f4311b2b00f29dc1ef6ee36f8e99d42d12d (diff)
[IMP] models: optimize `_is_an_ordinary_table`
The queries made by the method `_is_an_ordinary_table` represent about 8% of the time to do a full Odoo installation. Use a cached query for all tables on the registry to reduce that time to some negligible amount. closes odoo/odoo#39262 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Diffstat (limited to 'odoo/modules')
-rw-r--r--odoo/modules/registry.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py
index 5df1a7b61f0..51ea759fbbb 100644
--- a/odoo/modules/registry.py
+++ b/odoo/modules/registry.py
@@ -109,6 +109,7 @@ class Registry(Mapping):
self._init = True
self._assertion_report = assertion_report.assertion_report()
self._fields_by_model = None
+ self._ordinary_tables = None
self._post_init_queue = deque()
# modules fully loaded (maintained during init phase by `loading` module)
@@ -315,6 +316,8 @@ class Registry(Mapping):
model._auto_init()
model.init()
+ self._ordinary_tables = None
+
while self._post_init_queue:
func = self._post_init_queue.popleft()
func()
@@ -363,6 +366,24 @@ class Registry(Mapping):
for model in self.models.values():
model.clear_caches()
+ def is_an_ordinary_table(self, model):
+ """ Return whether the given model has an ordinary table. """
+ if self._ordinary_tables is None:
+ cr = model.env.cr
+ query = """
+ SELECT c.relname
+ FROM pg_class c
+ JOIN pg_namespace n ON (n.oid = c.relnamespace)
+ WHERE c.relname IN %s
+ AND c.relkind = 'r'
+ AND n.nspname = 'public'
+ """
+ tables = tuple(m._table for m in self.models.values())
+ cr.execute(query, [tables])
+ self._ordinary_tables = {row[0] for row in cr.fetchall()}
+
+ return model._table in self._ordinary_tables
+
def setup_signaling(self):
""" Setup the inter-process signaling on this registry. """
if self.in_test_mode():