From c22b7eb52a67a8437a0f814d955a3b6ed7e0dbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 19 May 2012 15:37:35 +0200 Subject: [PATCH] Use one record pool per group Having a global pool has some side effect between tabs. So it is better to get read optimization only inside one tab by using a pool on the main group. issue2582 review370002 (transplanted from c025b45e7c70bc262ddab7bb680b4260725da966) --- tryton/gui/window/view_form/model/group.py | 6 ++++++ tryton/gui/window/view_form/model/record.py | 23 ++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index dae254d2c2..089882af9b 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -1,5 +1,10 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. +try: + from weakref import WeakSet +except ImportError: + from weakrefset import WeakSet + from record import Record from field import Field, O2MField from tryton.signal_event import SignalEvent @@ -36,6 +41,7 @@ class Group(SignalEvent, list): self.__id2record = {} self.__field_childs = None self.exclude_field = None + self.pool = WeakSet() @property def domain(self): diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index 874615ed12..cf3458ce5a 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -1,10 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -try: - from weakref import WeakSet -except ImportError: - from weakrefset import WeakSet -from collections import defaultdict import tryton.rpc as rpc from tryton.signal_event import SignalEvent import tryton.common as common @@ -13,8 +8,6 @@ import field as fields from functools import reduce from tryton.common import RPCExecute, RPCException -POOL = defaultdict(WeakSet) - class Record(SignalEvent): @@ -42,7 +35,7 @@ class Record(SignalEvent): self.autocompletion = {} self.exception = False self.destroyed = False - POOL[model_name].add(self) + self.pool.add(self) def __getitem__(self, name): if name not in self._loaded and self.id >= 0: @@ -74,7 +67,7 @@ class Record(SignalEvent): n += 1 record_context = self.context_get() if loading == 'eager' and len(id2record) < 80: - for record in POOL[self.model_name]: + for record in self.pool: if (name not in record._loaded and record.id >= 0 and record.id not in id2record @@ -131,6 +124,14 @@ class Record(SignalEvent): def modified(self): return bool(self.modified_fields) + @property + def pool(self): + group = self.group + while (group.parent is not None + and group.parent.model_name == self.model_name): + group = group.parent + return group.pool + @property def parent(self): return self.group.parent @@ -576,6 +577,8 @@ class Record(SignalEvent): return self.attachment_count def destroy(self): + # Get reference to pool before unref group + pool = self.pool for v in self.value.itervalues(): if hasattr(v, 'destroy'): v.destroy() @@ -584,4 +587,4 @@ class Record(SignalEvent): self.value = None self.next = None self.destroyed = True - POOL[self.model_name].remove(self) + pool.remove(self)