Skip to content

Commit 2730ac3

Browse files
author
Ralf Schlatterbeck
committed
- optimisation for date:
if the database provides us with a datetime object, use that for creation of the roundup Date object -- don't convert to string first
1 parent 0d41c5b commit 2730ac3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

roundup/backends/rdbms_common.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
__docformat__ = 'restructuredtext'
5353

5454
# standard python modules
55-
import sys, os, time, re, errno, weakref, copy, logging
55+
import sys, os, time, re, errno, weakref, copy, logging, datetime
5656

5757
# roundup modules
5858
from roundup import hyperdb, date, password, roundupdb, security, support
@@ -62,6 +62,7 @@
6262
from roundup.support import reversed
6363
from roundup.i18n import _
6464

65+
6566
# support
6667
from roundup.backends.blobfiles import FileStorage
6768
try:
@@ -90,6 +91,13 @@ def _bool_cvt(value):
9091
# assume it's a number returned from the db API
9192
return int(value)
9293

94+
def date_to_hyperdb_value(d):
95+
""" convert date d to a roundup date """
96+
if isinstance (d, datetime.datetime):
97+
return date.Date(d)
98+
return date.Date (str(d).replace(' ', '.'))
99+
100+
93101
def connection_dict(config, dbnamestr=None):
94102
""" Used by Postgresql and MySQL to detemine the keyword args for
95103
opening the database connection."""
@@ -1039,7 +1047,7 @@ def setnode(self, classname, nodeid, values, multilink_changes={}):
10391047

10401048
sql_to_hyperdb_value = {
10411049
hyperdb.String : str,
1042-
hyperdb.Date : lambda x:date.Date(str(x).replace(' ', '.')),
1050+
hyperdb.Date : date_to_hyperdb_value,
10431051
# hyperdb.Link : int, # XXX numeric ids
10441052
hyperdb.Link : str,
10451053
hyperdb.Interval : date.Interval,
@@ -2660,6 +2668,7 @@ def filter_iter(self, search_matches, filterspec, sort=[], group=[]):
26602668
name = p.name
26612669
assert (name)
26622670
classes[key][name] = p
2671+
p.to_hyperdb = self.db.to_hyperdb_value(p.propclass.__class__)
26632672
while True:
26642673
row = cursor.fetchone()
26652674
if not row: break
@@ -2674,8 +2683,7 @@ def filter_iter(self, search_matches, filterspec, sort=[], group=[]):
26742683
for propname, p in pt.iteritems():
26752684
value = row[p.sql_idx]
26762685
if value is not None:
2677-
cls = p.propclass.__class__
2678-
value = self.db.to_hyperdb_value(cls)(value)
2686+
value = p.to_hyperdb(value)
26792687
node[propname] = value
26802688
self.db._cache_save(key, node)
26812689
yield str(row[0])

0 commit comments

Comments
 (0)