Commit 6e4afa6f authored by Vincent Pelletier's avatar Vincent Pelletier

Fix transaction iterator.

Record is expected to contain the TID of previous transaction which
modified given object. This is not the meaning of 3rd value returned by
_load (the TID of the next transaction modifying object).
So, instead, cache the last TID of each object, until there is no next
transaction modifying them.*
As this can become a memory problem with big number of objects, add a TODO.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2262 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent b9a43bfa
...@@ -39,7 +39,8 @@ class Record(BaseStorage.DataRecord): ...@@ -39,7 +39,8 @@ class Record(BaseStorage.DataRecord):
class Transaction(BaseStorage.TransactionRecord): class Transaction(BaseStorage.TransactionRecord):
""" Transaction object yielded by the NEO iterator """ """ Transaction object yielded by the NEO iterator """
def __init__(self, app, tid, status, user, desc, ext, oid_list): def __init__(self, app, tid, status, user, desc, ext, oid_list,
prev_serial_dict):
self.app = app self.app = app
self.tid = tid self.tid = tid
self.status = status self.status = status
...@@ -48,6 +49,7 @@ class Transaction(BaseStorage.TransactionRecord): ...@@ -48,6 +49,7 @@ class Transaction(BaseStorage.TransactionRecord):
self._extension = ext self._extension = ext
self.oid_list = oid_list self.oid_list = oid_list
self.history = [] self.history = []
self.prev_serial_dict = prev_serial_dict
def __iter__(self): def __iter__(self):
return self return self
...@@ -60,9 +62,13 @@ class Transaction(BaseStorage.TransactionRecord): ...@@ -60,9 +62,13 @@ class Transaction(BaseStorage.TransactionRecord):
raise StopIteration raise StopIteration
oid = self.oid_list.pop() oid = self.oid_list.pop()
# load an object # load an object
result = app._load(oid, serial=self.tid) data, _, next_tid = app._load(oid, serial=self.tid)
data, start_serial, end_serial = result record = Record(oid, self.tid, '', data,
record = Record(oid, self.tid, '', data, end_serial) self.prev_serial_dict.get(oid))
if next_tid is None:
self.prev_serial_dict.pop(oid, None)
else:
self.prev_serial_dict[oid] = self.tid
return record return record
def __str__(self): def __str__(self):
...@@ -84,6 +90,9 @@ class Iterator(object): ...@@ -84,6 +90,9 @@ class Iterator(object):
# index of current iteration # index of current iteration
self._index = 0 self._index = 0
self._closed = False self._closed = False
# OID -> previous TID mapping
# TODO: prune old entries while walking ?
self._prev_serial_dict = {}
def __iter__(self): def __iter__(self):
return self return self
...@@ -113,7 +122,8 @@ class Iterator(object): ...@@ -113,7 +122,8 @@ class Iterator(object):
desc = txn['description'] desc = txn['description']
oid_list = txn['oids'] oid_list = txn['oids']
extension = {} # as expected by the ZODB extension = {} # as expected by the ZODB
txn = Transaction(self.app, tid, ' ', user, desc, extension, oid_list) txn = Transaction(self.app, tid, ' ', user, desc, extension, oid_list,
self._prev_serial_dict)
return txn return txn
def __str__(self): def __str__(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment