cubicweb/server/querier.py
changeset 12062 601d65193619
parent 12060 0cdf5fafd234
child 12172 8bb323eb6859
--- a/cubicweb/server/querier.py	Wed Mar 15 08:30:27 2017 +0100
+++ b/cubicweb/server/querier.py	Fri Mar 17 07:32:48 2017 +0100
@@ -23,7 +23,7 @@
 from itertools import repeat
 
 from six import text_type, string_types, integer_types
-from six.moves import range
+from six.moves import range, zip
 
 from rql import RQLSyntaxError, CoercionError
 from rql.stmts import Union
@@ -477,15 +477,24 @@
 
     def set_schema(self, schema):
         self.schema = schema
-        repo = self._repo
-        self.rql_cache = RQLCache(repo, schema)
-        rqlhelper = repo.vreg.rqlhelper
+        self.clear_caches()
+        rqlhelper = self._repo.vreg.rqlhelper
         self._annotate = rqlhelper.annotate
         # rql planner
         self._planner = SSPlanner(schema, rqlhelper)
         # sql generation annotator
         self.sqlgen_annotate = SQLGenAnnotator(schema).annotate
 
+    def clear_caches(self, eids=None, etypes=None):
+        if eids is None:
+            self.rql_cache = RQLCache(self._repo, self.schema)
+        else:
+            cache = self.rql_cache
+            for eid, etype in zip(eids, etypes):
+                cache.pop(('Any X WHERE X eid %s' % eid,), None)
+                if etype is not None:
+                    cache.pop(('%s X WHERE X eid %s' % (etype, eid),), None)
+
     def plan_factory(self, rqlst, args, cnx):
         """create an execution plan for an INSERT RQL query"""
         if rqlst.TYPE == 'insert':