From 07198b9a4f82ccc0158cd14468543f1fb2dbf5db Mon Sep 17 00:00:00 2001 From: jbjourget-b <137054756+jbjourget-b@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:30:54 +0100 Subject: [PATCH] [FIX] base: Update wrong cache invalidation Avoid invalidating cache when not needed. This improves a lot performances. Closes #143403 Fixes a bug which causes that: self.flush() and self.clear_caches() were called on every property write/update and delete. Known at least in V14/15/16/17. closes odoo/odoo#145171 Related: odoo/enterprise#52207 Signed-off-by: Raphael Collet --- doc/cla/individual/jbjourget-b.md | 11 +++++++++++ odoo/addons/base/models/ir_property.py | 15 ++------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 doc/cla/individual/jbjourget-b.md diff --git a/doc/cla/individual/jbjourget-b.md b/doc/cla/individual/jbjourget-b.md new file mode 100644 index 0000000000000..e16c6a92a26ad --- /dev/null +++ b/doc/cla/individual/jbjourget-b.md @@ -0,0 +1,11 @@ +France, 2023-11-27 + +I hereby agree to the terms of the Odoo Individual Contributor License +Agreement v1.0. + +I declare that I am authorized and able to make this agreement and sign this +declaration. + +Signed, + +Jean-BenoƮt Jourget 137054756+jbjourget-b@users.noreply.github.com https://github.com/jbjourget-b diff --git a/odoo/addons/base/models/ir_property.py b/odoo/addons/base/models/ir_property.py index 525751302d26e..7a379785ac100 100644 --- a/odoo/addons/base/models/ir_property.py +++ b/odoo/addons/base/models/ir_property.py @@ -111,12 +111,7 @@ def write(self, values): # we're writing a res_id=False on any record default_set = False if self._ids: - self.env.cr.execute( - 'SELECT EXISTS (SELECT 1 FROM ir_property WHERE id in %s AND res_id IS NULL)', [self._ids]) - default_set = self.env.cr.rowcount == 1 or any( - v.get('res_id') is False - for v in values - ) + default_set = values.get('res_id') is False or any(not p.res_id for p in self) r = super(Property, self).write(self._update_values(values)) if default_set: # DLE P44: test `test_27_company_dependent` @@ -139,13 +134,7 @@ def create(self, vals_list): return r def unlink(self): - default_deleted = False - if self._ids: - self.env.cr.execute( - 'SELECT EXISTS (SELECT 1 FROM ir_property WHERE id in %s)', - [self._ids] - ) - default_deleted = self.env.cr.rowcount == 1 + default_deleted = any(not p.res_id for p in self) r = super().unlink() if default_deleted: self.clear_caches()