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)
This commit is contained in:
1 parent
9ed60d92ad
commit
c22b7eb52a
2 files changed
+19
-10
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user