Skip to content

Commit 473d87d

Browse files
author
Ralf Schlatterbeck
committed
- refactor: move import_journal to hyperdb
.-- it was reimplemented in back_anydbm and rdbms_common and was already inconsistent -- and it doen't have any backend dependencies itself. Interestingly this now fails a test for memorydb (but passes for anydbm: Huh?)
1 parent ca375fc commit 473d87d

File tree

4 files changed

+51
-79
lines changed

4 files changed

+51
-79
lines changed

CHANGES.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ 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.
47+
- lower memory footprint for (journal-) import
4948

5049

5150
2010-07-12 1.4.15

roundup/backends/back_anydbm.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,34 +2000,6 @@ def export_journals(self):
20002000
repr(action), repr(params)])
20012001
return r
20022002

2003-
def import_journals(self, entries):
2004-
"""Import a class's journal.
2005-
2006-
Uses setjournal() to set the journal for each item."""
2007-
properties = self.getprops()
2008-
d = {}
2009-
for l in entries:
2010-
nodeid, jdate, user, action, params = tuple(map(eval, l))
2011-
r = d.setdefault(nodeid, [])
2012-
if action == 'set':
2013-
for propname, value in params.iteritems():
2014-
prop = properties[propname]
2015-
if value is None:
2016-
pass
2017-
elif isinstance(prop, hyperdb.Date):
2018-
value = date.Date(value)
2019-
elif isinstance(prop, hyperdb.Interval):
2020-
value = date.Interval(value)
2021-
elif isinstance(prop, hyperdb.Password):
2022-
pwd = password.Password()
2023-
pwd.unpack(value)
2024-
value = pwd
2025-
params[propname] = value
2026-
r.append((nodeid, date.Date(jdate), user, action, params))
2027-
2028-
for nodeid, l in d.iteritems():
2029-
self.db.setjournal(self.classname, nodeid, l)
2030-
20312003
class FileClass(hyperdb.FileClass, Class):
20322004
"""This class defines a large chunk of data. To support this, it has a
20332005
mandatory String property "content" which is typically saved off

roundup/backends/rdbms_common.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,55 +2641,6 @@ def export_journals(self):
26412641
r.append(list(map(repr, l)))
26422642
return r
26432643

2644-
def import_journals(self, entries):
2645-
"""Import a class's journal.
2646-
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."""
2652-
properties = self.getprops()
2653-
a = []
2654-
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:
2664-
nodeid, jdate, user, action, params = map(eval, l)
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-
2672-
if action == 'set':
2673-
for propname, value in params.iteritems():
2674-
prop = properties[propname]
2675-
if value is None:
2676-
pass
2677-
elif isinstance(prop, Date):
2678-
value = date.Date(value)
2679-
elif isinstance(prop, Interval):
2680-
value = date.Interval(value)
2681-
elif isinstance(prop, Password):
2682-
pwd = password.Password()
2683-
pwd.unpack(value)
2684-
value = pwd
2685-
params[propname] = value
2686-
elif action == 'create' and params:
2687-
# old tracker with data stored in the create!
2688-
params = {}
2689-
r.append((nodeid, date.Date(jdate), user, action, params))
2690-
if r:
2691-
self.db.setjournal(self.classname, nodeid, r)
2692-
26932644
class FileClass(hyperdb.FileClass, Class):
26942645
"""This class defines a large chunk of data. To support this, it has a
26952646
mandatory String property "content" which is typically saved off

roundup/hyperdb.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,56 @@ def export_propnames(self):
12371237
propnames = self.getprops().keys()
12381238
propnames.sort()
12391239
return propnames
1240+
1241+
def import_journals(self, entries):
1242+
"""Import a class's journal.
1243+
1244+
Uses setjournal() to set the journal for each item.
1245+
Strategy for import: Sort first by id, then import journals for
1246+
each id, this way the memory footprint is a lot smaller than the
1247+
initial implementation which stored everything in a big hash by
1248+
id and then proceeded to import journals for each id."""
1249+
properties = self.getprops()
1250+
a = []
1251+
for l in entries:
1252+
# first element in sorted list is the (numeric) id
1253+
# in python2.4 and up we would use sorted with a key...
1254+
a.append ((int (l [0].strip ("'")), l))
1255+
a.sort ()
1256+
1257+
1258+
last = 0
1259+
r = []
1260+
for n, l in a:
1261+
nodeid, jdate, user, action, params = map(eval, l)
1262+
assert (str(n) == nodeid)
1263+
if n != last:
1264+
if r:
1265+
self.db.setjournal(self.classname, nodeid, r)
1266+
last = n
1267+
r = []
1268+
1269+
if action == 'set':
1270+
for propname, value in params.iteritems():
1271+
prop = properties[propname]
1272+
if value is None:
1273+
pass
1274+
elif isinstance(prop, Date):
1275+
value = date.Date(value)
1276+
elif isinstance(prop, Interval):
1277+
value = date.Interval(value)
1278+
elif isinstance(prop, Password):
1279+
pwd = password.Password()
1280+
pwd.unpack(value)
1281+
value = pwd
1282+
params[propname] = value
1283+
elif action == 'create' and params:
1284+
# old tracker with data stored in the create!
1285+
params = {}
1286+
r.append((nodeid, date.Date(jdate), user, action, params))
1287+
if r:
1288+
self.db.setjournal(self.classname, nodeid, r)
1289+
12401290
#
12411291
# convenience methods
12421292
#

0 commit comments

Comments
 (0)