[repo] Introduce a clear_caches method on the Querier class
that is called from repository's clear_caches.
--- a/cubicweb/devtools/__init__.py Wed Mar 15 08:30:27 2017 +0100
+++ b/cubicweb/devtools/__init__.py Fri Mar 17 07:32:48 2017 +0100
@@ -124,7 +124,6 @@
if repo._needs_refresh:
for cnxset in repo.cnxsets:
cnxset.reconnect()
- repo.querier.set_schema(repo.schema)
repo.clear_caches()
repo._needs_refresh = False
--- 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':
--- a/cubicweb/server/repository.py Wed Mar 15 08:30:27 2017 +0100
+++ b/cubicweb/server/repository.py Fri Mar 17 07:32:48 2017 +0100
@@ -667,15 +667,13 @@
else:
etypes = []
etcache = self._type_cache
- rqlcache = self.querier.rql_cache
for eid in eids:
try:
etype = etcache.pop(int(eid)) # may be a string in some cases
- rqlcache.pop(('%s X WHERE X eid %s' % (etype, eid),), None)
except KeyError:
etype = None
- rqlcache.pop(('Any X WHERE X eid %s' % eid,), None)
etypes.append(etype)
+ self.querier.clear_caches(eids, etypes)
self.system_source.clear_caches(eids, etypes)
def type_from_eid(self, eid, cnx):