@@ -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
26752693class FileClass (hyperdb .FileClass , Class ):
26762694 """This class defines a large chunk of data. To support this, it has a
0 commit comments