Skip to content

Commit ca375fc

Browse files
author
Ralf Schlatterbeck
committed
- lower memory footprint for (journal-) import
.-- only for rdbms backends, other backends shouldn't have that much data anyway.
1 parent dd45cc6 commit ca375fc

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Fixed:
4444
Thanks to Benni B�rmann for reporting.
4545
- Allow search_popup macro to work with all db classes, issue2550567
4646
(thanks John Kristensen)
47+
- lower memory footprint for (journal-) import -- only for rdbms
48+
backends, other backends shouldn't have that much data anyway.
4749

4850

4951
2010-07-12 1.4.15

roundup/backends/rdbms_common.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,12 +2644,31 @@ def export_journals(self):
26442644
def import_journals(self, entries):
26452645
"""Import a class's journal.
26462646
2647-
Uses setjournal() to set the journal for each item."""
2647+
Uses setjournal() to set the journal for each item.
2648+
Strategy for import: Sort first by id, then import journals for
2649+
each id, this way the memory footprint is a lot smaller than the
2650+
initial implementation which stored everything in a big hash by
2651+
id and then proceeded to import journals for each id."""
26482652
properties = self.getprops()
2649-
d = {}
2653+
a = []
26502654
for l in entries:
2655+
# first element in sorted list is the (numeric) id
2656+
# in python2.4 and up we would use sorted with a key...
2657+
a.append ((int (l [0].strip ("'")), l))
2658+
a.sort ()
2659+
2660+
2661+
last = 0
2662+
r = []
2663+
for n, l in a:
26512664
nodeid, jdate, user, action, params = map(eval, l)
2652-
r = d.setdefault(nodeid, [])
2665+
assert (str(n) == nodeid)
2666+
if n != last:
2667+
if r:
2668+
self.db.setjournal(self.classname, nodeid, r)
2669+
last = n
2670+
r = []
2671+
26532672
if action == 'set':
26542673
for propname, value in params.iteritems():
26552674
prop = properties[propname]
@@ -2668,9 +2687,8 @@ def import_journals(self, entries):
26682687
# old tracker with data stored in the create!
26692688
params = {}
26702689
r.append((nodeid, date.Date(jdate), user, action, params))
2671-
2672-
for nodeid, l in d.iteritems():
2673-
self.db.setjournal(self.classname, nodeid, l)
2690+
if r:
2691+
self.db.setjournal(self.classname, nodeid, r)
26742692

26752693
class FileClass(hyperdb.FileClass, Class):
26762694
"""This class defines a large chunk of data. To support this, it has a

0 commit comments

Comments
 (0)