summaryrefslogtreecommitdiff
path: root/odoo/sql_db.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2019-08-14 07:35:49 +0000
committerDenis Ledoux <dle@odoo.com>2019-08-20 12:43:59 +0000
commit9920f20e4c7753bc17bea71dea3a90f7de687196 (patch)
tree6a3d0258c10a8ccb1d85949ddafdeb070de78121 /odoo/sql_db.py
parente28d3aa4d3851d72deba08c236072d002f83216a (diff)
[IMP] models: ORM speedup
This branch is the combination of several optimizations in the ORM: * store field values once in the cache: the cache reflects more faithfully the database, only fields that explicitly depend on the context have an extra indirection in the cache; * delay recomputations by default: use method `recompute` to explicitly flush out pending recomputations; * delay updates in method `write`: updates are stored in a data structure that can be flushed efficiently to the database with method `flush` (which also flush out recomputations); * make method `modified` take advantage of inverse fields to inverse dependencies; * filter records by evaluating a domain on records in Python; * a computed field with `readonly=False` behaves like a normal field with an onchange method; * computed fields are computed in superuser mode by default. Work done by Toufik Ben Jaa, Raphael Collet, Denis Ledoux and Fabien Pinckaers. closes odoo/odoo#35659 Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
Diffstat (limited to 'odoo/sql_db.py')
-rw-r--r--odoo/sql_db.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/odoo/sql_db.py b/odoo/sql_db.py
index debc9f48c42..ed5cf07884d 100644
--- a/odoo/sql_db.py
+++ b/odoo/sql_db.py
@@ -22,6 +22,8 @@ from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ
from psycopg2.pool import PoolError
from werkzeug import urls
+from odoo.api import Environment
+
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
_logger = logging.getLogger(__name__)
@@ -367,6 +369,10 @@ class Cursor(object):
def commit(self):
""" Perform an SQL `COMMIT`
"""
+ for env in Environment.envs:
+ if env.cr is self:
+ env['base'].flush()
+ break
result = self._cnx.commit()
for func in self._pop_event_handlers()['commit']:
func()
@@ -376,6 +382,10 @@ class Cursor(object):
def rollback(self):
""" Perform an SQL `ROLLBACK`
"""
+ for env in Environment.envs:
+ if env.cr is self:
+ env.clear()
+ break
result = self._cnx.rollback()
for func in self._pop_event_handlers()['rollback']:
func()
@@ -463,9 +473,17 @@ class TestCursor(object):
_logger.debug("TestCursor.autocommit(%r) does nothing", on)
def commit(self):
+ for env in Environment.envs:
+ if env.cr is self:
+ env['base'].flush()
+ break
self._cursor.execute('SAVEPOINT "%s"' % self._savepoint)
def rollback(self):
+ for env in Environment.envs:
+ if env.cr is self:
+ env.clear()
+ break
self._cursor.execute('ROLLBACK TO SAVEPOINT "%s"' % self._savepoint)
def __enter__(self):