# HG changeset patch # User Sylvain Thénault # Date 1298280539 -3600 # Node ID d3d7ff6ab54c6e845995d77ff250aef7034aa161 # Parent 2c65dd2cbfffdf1360c807675f4590a970d81ef0 [repo querier] fix rqlst cache no limit issue, comment the code diff -r 2c65dd2cbfff -r d3d7ff6ab54c server/querier.py --- a/server/querier.py Fri Feb 18 18:18:42 2011 +0100 +++ b/server/querier.py Mon Feb 21 10:28:59 2011 +0100 @@ -586,12 +586,12 @@ def set_schema(self, schema): self.schema = schema repo = self._repo - # rql st and solution cache. Don't bother using a Cache instance: we - # should have a limited number of queries in there, since there are no - # entries in this cache for user queries (which have no args) - self._rql_cache = {} - # rql cache key cache - self._rql_ck_cache = Cache(repo.config['rql-cache-size']) + # rql st and solution cache. + self._rql_cache = Cache(repo.config['rql-cache-size']) + # rql cache key cache. Don't bother using a Cache instance: we should + # have a limited number of queries in there, since there are no entries + # in this cache for user queries (which have no args) + self._rql_ck_cache = {} # some cache usage stats self.cache_hit, self.cache_miss = 0, 0 # rql parsing / analysing helper @@ -656,11 +656,15 @@ print '*'*80 print 'querier input', rql, args # parse the query and binds variables + cachekey = rql try: - cachekey = rql if args: + # search for named args in query which are eids (hence + # influencing query's solutions) eidkeys = self._rql_ck_cache[rql] if eidkeys: + # if there are some, we need a better cache key, eg (rql + + # entity type of each eid) try: cachekey = self._repo.querier_cache_key(session, rql, args, eidkeys) @@ -674,15 +678,20 @@ self.cache_miss += 1 rqlst = self.parse(rql) try: + # compute solutions for rqlst and return named args in query + # which are eids. Notice that if you may not need `eidkeys`, we + # have to compute solutions anyway (kept as annotation on the + # tree) eidkeys = self.solutions(session, rqlst, args) except UnknownEid: # we want queries such as "Any X WHERE X eid 9999" return an # empty result instead of raising UnknownEid return empty_rset(rql, args, rqlst) - self._rql_ck_cache[rql] = eidkeys - if eidkeys: - cachekey = self._repo.querier_cache_key(session, rql, args, - eidkeys) + if args and not rql in self._rql_ck_cache: + self._rql_ck_cache[rql] = eidkeys + if eidkeys: + cachekey = self._repo.querier_cache_key(session, rql, args, + eidkeys) self._rql_cache[cachekey] = rqlst orig_rqlst = rqlst if rqlst.TYPE != 'select':