From 1140618c3a16bbabc7e367f3d8e0be0b57d8b2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 31 Jul 2014 19:41:31 +0200 Subject: [PATCH] Remove grand parent pool for sibling Walking the grand parent pool could be expensif on large tree to prefetch some records, so it seems to be a better strategy to limit to sibling. issue4085 review5461003 --- tryton/gui/window/view_form/model/group.py | 3 -- tryton/gui/window/view_form/model/record.py | 59 ++++++++------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index 7f581efd9a..ad60995b58 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -1,7 +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. -from weakref import WeakSet - from record import Record from field import Field, O2MField, M2OField, ReferenceField from tryton.signal_event import SignalEvent @@ -37,7 +35,6 @@ class Group(SignalEvent, list): self.__id2record = {} self.__field_childs = None self.exclude_field = None - self.pool = WeakSet() self.skip_model_access = False if self.parent and self.parent.model_name == model_name: diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index e7ec55edab..28696c9785 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -36,7 +36,6 @@ class Record(SignalEvent): self.autocompletion = {} self.exception = False self.destroyed = False - self.pool.add(self) def __getitem__(self, name): if name not in self._loaded and self.id >= 0: @@ -78,35 +77,34 @@ class Record(SignalEvent): def filter_group(record): return name not in record._loaded and record.id >= 0 - def filter_pool(record): + def filter_parent_group(record): return (filter_group(record) and record.id not in id2record - and record.context_get() == record_context) + and ((record.group == self.group) + # Don't compute context for same group + or (record.context_get() == record_context))) if self.parent: - pool = list(self.pool) + group = sum(self.parent.group.children, []) + filter_ = filter_parent_group else: - # Don't look at the pool if it is the root - pool = [] - for group, filter_ in ( - (self.group, filter_group), - (pool, filter_pool), - ): - if self in group: - idx = group.index(self) - length = len(group) - n = 1 - while len(id2record) < limit and (idx - n >= 0 - or idx + n < length) and n < 2 * limit: - if idx - n >= 0: - record = group[idx - n] - if filter_(record): - id2record[record.id] = record - if idx + n < length: - record = group[idx + n] - if filter_(record): - id2record[record.id] = record - n += 1 + group = self.group + filter_ = filter_group + if self in group: + idx = group.index(self) + length = len(group) + n = 1 + while len(id2record) < limit and (idx - n >= 0 + or idx + n < length) and n < 2 * limit: + if idx - n >= 0: + record = group[idx - n] + if filter_(record): + id2record[record.id] = record + if idx + n < length: + record = group[idx + n] + if filter_(record): + id2record[record.id] = record + n += 1 ctx = record_context.copy() ctx.update(dict(('%s.%s' % (self.model_name, fname), 'size') @@ -140,14 +138,6 @@ 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 @@ -625,11 +615,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() super(Record, self).destroy() self.destroyed = True - pool.remove(self)