cache result of the COUNT query used to see if a non unique attribute may be used as rest path on the entity instance to avoid recomputing it later
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 26 Jan 2010 13:27:40 +0100
changeset 4363 5c18d82042fb
parent 4362 817851a77e27
child 4364 766359c69f2f
cache result of the COUNT query used to see if a non unique attribute may be used as rest path on the entity instance to avoid recomputing it later
entity.py
--- a/entity.py	Tue Jan 26 13:26:41 2010 +0100
+++ b/entity.py	Tue Jan 26 13:27:40 2010 +0100
@@ -316,9 +316,12 @@
                 path += '/eid'
             elif needcheck:
                 # make sure url is not ambiguous
-                rql = 'Any COUNT(X) WHERE X is %s, X %s %%(value)s' % (
-                    etype, mainattr)
-                nbresults = self._cw.execute(rql, {'value' : value})[0][0]
+                try:
+                    nbresults = self.__unique
+                except AttributeError:
+                    rql = 'Any COUNT(X) WHERE X is %s, X %s %%(value)s' % (
+                        etype, mainattr)
+                    nbresults = self.__unique = self._cw.execute(rql, {'value' : value})[0][0]
                 if nbresults != 1: # ambiguity?
                     mainattr = 'eid'
                     path += '/eid'