[selector] more efficient rql_condition by simply retreiving COUNT()
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 12 Oct 2010 19:10:43 +0200
changeset 6457 3234d8d6e264
parent 6456 150246e77cda
child 6458 e4eb95d86172
[selector] more efficient rql_condition by simply retreiving COUNT()
selectors.py
--- a/selectors.py	Tue Oct 12 19:10:08 2010 +0200
+++ b/selectors.py	Tue Oct 12 19:10:43 2010 +0200
@@ -1143,9 +1143,9 @@
     def __init__(self, expression, once_is_enough=False):
         super(rql_condition, self).__init__(once_is_enough)
         if 'U' in frozenset(split_expression(expression)):
-            rql = 'Any X WHERE X eid %%(x)s, U eid %%(u)s, %s' % expression
+            rql = 'Any COUNT(X) WHERE X eid %%(x)s, U eid %%(u)s, %s' % expression
         else:
-            rql = 'Any X WHERE X eid %%(x)s, %s' % expression
+            rql = 'Any COUNT(X) WHERE X eid %%(x)s, %s' % expression
         self.rql = rql
 
     def __repr__(self):
@@ -1153,8 +1153,8 @@
 
     def score(self, req, rset, row, col):
         try:
-            return len(req.execute(self.rql, {'x': rset[row][col],
-                                              'u': req.user.eid}))
+            return req.execute(self.rql, {'x': rset[row][col],
+                                          'u': req.user.eid})[0][0]
         except Unauthorized:
             return 0