[rset] kill the rset._rqlst cache
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 27 May 2014 18:47:24 +0200
changeset 10087 ed0b076c119b
parent 10086 98bc2ca1a816
child 10088 ac63f7ec5af0
[rset] kill the rset._rqlst cache Right now it "works" for the standard, internal uses. However when we will fold ClientConnection and Connection, it will hurt, because suddenly we get more cache hits, and the following situation would become commonplace: * there is an un-annotated _rqlst given by the querier * some view (e.g. facets) requests the .syntax_tree, which takes a copy of _rqlst * the view actually expects the rql syntax tree to be annotated, but it was not, hence we crash. Related to #3837233.
repoapi.py
rset.py
server/querier.py
test/unittest_rset.py
--- a/repoapi.py	Tue Jun 03 18:03:43 2014 +0200
+++ b/repoapi.py	Tue May 27 18:47:24 2014 +0200
@@ -212,10 +212,6 @@
         # Connection object
         rset = self._cnx.execute(*args, **kwargs)
         rset.req = self
-        # XXX keep the same behavior as the old dbapi
-        # otherwise multiple tests break.
-        # The little internet kitten is very sad about this situation.
-        rset._rqlst = None
         return rset
 
     @_open_only
--- a/rset.py	Tue Jun 03 18:03:43 2014 +0200
+++ b/rset.py	Tue May 27 18:47:24 2014 +0200
@@ -19,6 +19,8 @@
 
 __docformat__ = "restructuredtext en"
 
+from warnings import warn
+
 from logilab.common.decorators import cached, clear_cache, copy_cache
 
 from rql import nodes, stmts
@@ -46,6 +48,9 @@
     """
 
     def __init__(self, results, rql, args=None, description=None, rqlst=None):
+        if rqlst is not None:
+            warn('[3.20] rqlst parameter is deprecated',
+                 DeprecationWarning, stacklevel=2)
         self.rows = results
         self.rowcount = results and len(results) or 0
         # original query and arguments
@@ -57,10 +62,6 @@
             self.description = []
         else:
             self.description = description
-        # parsed syntax tree
-        if rqlst is not None:
-            rqlst.schema = None # reset schema in case of pyro transfert
-        self._rqlst = rqlst
         # set to (limit, offset) when a result set is limited using the
         # .limit method
         self.limited = None
@@ -550,18 +551,11 @@
 
     @cached
     def syntax_tree(self):
-        """return the syntax tree (:class:`rql.stmts.Union`) for the originating
-        query. You can expect it to have solutions computed but it won't be
-        annotated (you usually don't need that for simple introspection).
+        """return the syntax tree (:class:`rql.stmts.Union`) for the
+        originating query. You can expect it to have solutions
+        computed and it will be properly annotated.
         """
-        if self._rqlst:
-            rqlst = self._rqlst.copy()
-            # to avoid transport overhead when pyro is used, the schema has been
-            # unset from the syntax tree
-            rqlst.schema = self.req.vreg.schema
-        else:
-            rqlst = self.req.vreg.parse(self.req, self.rql, self.args)
-        return rqlst
+        return self.req.vreg.parse(self.req, self.rql, self.args)
 
     @cached
     def column_types(self, col):
--- a/server/querier.py	Tue Jun 03 18:03:43 2014 +0200
+++ b/server/querier.py	Tue May 27 18:47:24 2014 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -577,7 +577,6 @@
                     cachekey = self._repo.querier_cache_key(cnx, rql, args,
                                                             eidkeys)
             self._rql_cache[cachekey] = rqlst
-        orig_rqlst = rqlst
         if rqlst.TYPE != 'select':
             if cnx.read_security:
                 check_no_password_selected(rqlst)
@@ -646,7 +645,7 @@
             # FIXME: get number of affected entities / relations on non
             # selection queries ?
         # return a result set object
-        return ResultSet(results, rql, args, descr, orig_rqlst)
+        return ResultSet(results, rql, args, descr)
 
     # these are overridden by set_log_methods below
     # only defining here to prevent pylint from complaining
--- a/test/unittest_rset.py	Tue Jun 03 18:03:43 2014 +0200
+++ b/test/unittest_rset.py	Tue May 27 18:47:24 2014 +0200
@@ -100,7 +100,7 @@
 
     def test_pickle(self):
         del self.rset.req
-        self.assertEqual(len(pickle.dumps(self.rset)), 392)
+        self.assertEqual(len(pickle.dumps(self.rset)), 376)
 
     def test_build_url(self):
         with self.admin_access.web_request() as req: