changeset 2734:1e70e58cf763 maint-0.7

merge from HEAD
author Richard Jones <richard@users.sourceforge.net>
date Fri, 08 Oct 2004 01:29:30 +0000
parents 0d8b3b5f40ea
children 89b276643bb5
files CHANGES.txt roundup/backends/rdbms_common.py
diffstat 2 files changed, 14 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Fri Oct 08 00:57:22 2004 +0000
+++ b/CHANGES.txt	Fri Oct 08 01:29:30 2004 +0000
@@ -20,6 +20,7 @@
 - date.Interval() now accepts an Interval as a spec (sf bug 1041266)
 - handle deleted properties in RDBMS history
 - apply timezone in correct direction in user input (sf bug 1013097)
+- more efficient find() in RDBMS (sf bug 1012781)
 
 
 2004-07-21 0.7.6
--- a/roundup/backends/rdbms_common.py	Fri Oct 08 00:57:22 2004 +0000
+++ b/roundup/backends/rdbms_common.py	Fri Oct 08 01:29:30 2004 +0000
@@ -1,4 +1,4 @@
-# $Id: rdbms_common.py,v 1.98.2.22 2004-10-08 00:57:22 richard Exp $
+# $Id: rdbms_common.py,v 1.98.2.23 2004-10-08 01:29:30 richard Exp $
 ''' Relational database (SQL) backend common code.
 
 Basics:
@@ -1953,8 +1953,8 @@
 
         # first, links
         a = self.db.arg
-        allvalues = (1,)
-        o = []
+        allvalues = ()
+        sql = []
         where = []
         for prop, values in propspec:
             if not isinstance(props[prop], hyperdb.Link):
@@ -1975,9 +1975,10 @@
                 allvalues += tuple(values)
                 s += '_%s in (%s)'%(prop, ','.join([a]*len(values)))
                 where.append('(' + s +')')
-        tables = ['_%s'%self.classname]
         if where:
-            o.append('(' + ' and '.join(where) + ')')
+            allvalues = (1, ) + allvalues
+            sql.append('''select id from _%s where  __retired__ <> %s
+                and %s'''%(self.classname, a, ' and '.join(where)))
 
         # now multilinks
         for prop, values in propspec:
@@ -1985,6 +1986,7 @@
                 continue
             if not values:
                 continue
+            allvalues += (1, )
             if type(values) is type(''):
                 allvalues += (values,)
                 s = a
@@ -1992,18 +1994,13 @@
                 allvalues += tuple(values.keys())
                 s = ','.join([a]*len(values))
             tn = '%s_%s'%(self.classname, prop)
-            tables.append(tn)
-            o.append('(id=%s.nodeid and %s.linkid in (%s))'%(tn, tn, s))
-
-        if not o:
+            sql.append('''select id from _%s, %s where  __retired__ <> %s
+                  and id = %s.nodeid and %s.linkid in (%s)'''%(self.classname,
+                  tn, a, tn, tn, s))
+
+        if not sql:
             return []
-        elif len(o) > 1:
-            o = '(' + ' or '.join(['(%s)'%i for i in o]) + ')'
-        else:
-            o = o[0]
-        t = ', '.join(tables)
-        sql = 'select distinct(id) from %s where __retired__ <> %s and %s'%(
-            t, a, o)
+        sql = ' union '.join(sql)
         self.db.sql(sql, allvalues)
         # XXX numeric ids
         l = [str(x[0]) for x in self.db.sql_fetchall()]

Roundup Issue Tracker: http://roundup-tracker.org/