Commit 8bc4c612 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

cache result of the COUNT query used to see if a non unique attribute may be...

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
parent 817851a77e27
...@@ -316,9 +316,12 @@ class Entity(AppObject, dict): ...@@ -316,9 +316,12 @@ class Entity(AppObject, dict):
path += '/eid' path += '/eid'
elif needcheck: elif needcheck:
# make sure url is not ambiguous # make sure url is not ambiguous
rql = 'Any COUNT(X) WHERE X is %s, X %s %%(value)s' % ( try:
etype, mainattr) nbresults = self.__unique
nbresults = self._cw.execute(rql, {'value' : value})[0][0] 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? if nbresults != 1: # ambiguity?
mainattr = 'eid' mainattr = 'eid'
path += '/eid' path += '/eid'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment