Code

Don't check for node's existence if we know it exists.
authorstefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2>
Thu, 12 Mar 2009 14:08:31 +0000 (14:08 +0000)
committerstefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2>
Thu, 12 Mar 2009 14:08:31 +0000 (14:08 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4187 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/backends/rdbms_common.py

index 26f78b61f6450afa6271cfc3a710e652dd3d14b1..7cb90fd3b28242f39110f32951f0111f5fc2f3e1 100644 (file)
@@ -1740,10 +1740,17 @@ class Class(hyperdb.Class):
 
                 # handle additions
                 for id in value:
-                    if not self.db.getclass(link_class).hasnode(id):
-                        raise IndexError, '%s has no node %s'%(link_class, id)
                     if id in l:
                         continue
+                    # We can safely check this condition after
+                    # checking that this is an addition to the
+                    # multilink since the condition was checked for
+                    # existing entries at the point they were added to
+                    # the multilink.  Since the hasnode call will
+                    # result in a SQL query, it is more efficient to
+                    # avoid the check if possible.
+                    if not self.db.getclass(link_class).hasnode(id):
+                        raise IndexError, '%s has no node %s'%(link_class, id)
                     # register the link with the newly linked node
                     if self.do_journal and self.properties[propname].do_journal:
                         self.db.addjournal(link_class, id, 'link',