# HG changeset patch # User Sylvain Thénault # Date 1488535983 -3600 # Node ID bff3be6eebeddcc4e17b6f7c018a2df13de29280 # Parent 1c7be7b62823bfd55ee73feba5580e14841cacd5 [querier] Turn repo.querier_cache_key into a private function of the querier module, only place where it's used. diff -r 1c7be7b62823 -r bff3be6eebed cubicweb/server/querier.py --- a/cubicweb/server/querier.py Tue Mar 14 10:34:03 2017 +0100 +++ b/cubicweb/server/querier.py Fri Mar 03 11:13:03 2017 +0100 @@ -30,7 +30,7 @@ from rql.nodes import ETYPE_PYOBJ_MAP, etype_from_pyobj, Relation, Exists, Not from yams import BASE_TYPES -from cubicweb import ValidationError, Unauthorized, UnknownEid +from cubicweb import ValidationError, Unauthorized, UnknownEid, QueryError from cubicweb.rqlrewrite import RQLRelationRewriter from cubicweb import Binary, server from cubicweb.rset import ResultSet @@ -546,8 +546,7 @@ # if there are some, we need a better cache key, eg (rql + # entity type of each eid) try: - cachekey = self._repo.querier_cache_key(cnx, rql, - args, eidkeys) + cachekey = _rql_cache_key(cnx, rql, args, eidkeys) except UnknownEid: # we want queries such as "Any X WHERE X eid 9999" # return an empty result instead of raising UnknownEid @@ -572,8 +571,7 @@ if args and rql not in self._rql_ck_cache: self._rql_ck_cache[rql] = eidkeys if eidkeys: - cachekey = self._repo.querier_cache_key(cnx, rql, args, - eidkeys) + cachekey = _rql_cache_key(cnx, rql, args, eidkeys) self._rql_cache[cachekey] = rqlst if rqlst.TYPE != 'select': if cnx.read_security: @@ -646,6 +644,24 @@ # only defining here to prevent pylint from complaining info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None + +def _rql_cache_key(cnx, rql, args, eidkeys): + cachekey = [rql] + type_from_eid = cnx.repo.type_from_eid + for key in sorted(eidkeys): + try: + etype = type_from_eid(args[key], cnx) + except KeyError: + raise QueryError('bad cache key %s (no value)' % key) + except TypeError: + raise QueryError('bad cache key %s (value: %r)' % ( + key, args[key])) + cachekey.append(etype) + # ensure eid is correctly typed in args + args[key] = int(args[key]) + return tuple(cachekey) + + from logging import getLogger from cubicweb import set_log_methods LOGGER = getLogger('cubicweb.querier') diff -r 1c7be7b62823 -r bff3be6eebed cubicweb/server/repository.py --- a/cubicweb/server/repository.py Tue Mar 14 10:34:03 2017 +0100 +++ b/cubicweb/server/repository.py Fri Mar 03 11:13:03 2017 +0100 @@ -685,21 +685,6 @@ self._type_cache[eid] = etype return etype - def querier_cache_key(self, cnx, rql, args, eidkeys): - cachekey = [rql] - for key in sorted(eidkeys): - try: - etype = self.type_from_eid(args[key], cnx) - except KeyError: - raise QueryError('bad cache key %s (no value)' % key) - except TypeError: - raise QueryError('bad cache key %s (value: %r)' % ( - key, args[key])) - cachekey.append(etype) - # ensure eid is correctly typed in args - args[key] = int(args[key]) - return tuple(cachekey) - def add_info(self, cnx, entity, source): """add type and source info for an eid into the system table, and index the entity with the full text index