server/querier.py
changeset 10477 ee21c559f94f
parent 10366 38c7598b5c61
child 10555 d8df2c7cff1a
equal deleted inserted replaced
10476:62251bfdfd79 10477:ee21c559f94f
    35 from cubicweb.utils import QueryCache, RepeatList
    35 from cubicweb.utils import QueryCache, RepeatList
    36 from cubicweb.server.rqlannotation import SQLGenAnnotator, set_qdata
    36 from cubicweb.server.rqlannotation import SQLGenAnnotator, set_qdata
    37 from cubicweb.server.ssplanner import READ_ONLY_RTYPES, add_types_restriction
    37 from cubicweb.server.ssplanner import READ_ONLY_RTYPES, add_types_restriction
    38 from cubicweb.server.edition import EditedEntity
    38 from cubicweb.server.edition import EditedEntity
    39 from cubicweb.server.ssplanner import SSPlanner
    39 from cubicweb.server.ssplanner import SSPlanner
       
    40 from cubicweb.statsd_logger import statsd_timeit, statsd_c
    40 
    41 
    41 ETYPE_PYOBJ_MAP[Binary] = 'Bytes'
    42 ETYPE_PYOBJ_MAP[Binary] = 'Bytes'
    42 
    43 
    43 
    44 
    44 def empty_rset(rql, args, rqlst=None):
    45 def empty_rset(rql, args, rqlst=None):
   514         """create an execution plan for an INSERT RQL query"""
   515         """create an execution plan for an INSERT RQL query"""
   515         if rqlst.TYPE == 'insert':
   516         if rqlst.TYPE == 'insert':
   516             return InsertPlan(self, rqlst, args, cnx)
   517             return InsertPlan(self, rqlst, args, cnx)
   517         return ExecutionPlan(self, rqlst, args, cnx)
   518         return ExecutionPlan(self, rqlst, args, cnx)
   518 
   519 
       
   520     @statsd_timeit
   519     def execute(self, cnx, rql, args=None, build_descr=True):
   521     def execute(self, cnx, rql, args=None, build_descr=True):
   520         """execute a rql query, return resulting rows and their description in
   522         """execute a rql query, return resulting rows and their description in
   521         a `ResultSet` object
   523         a `ResultSet` object
   522 
   524 
   523         * `rql` should be a Unicode string or a plain ASCII string
   525         * `rql` should be a Unicode string or a plain ASCII string
   556                         # we want queries such as "Any X WHERE X eid 9999"
   558                         # we want queries such as "Any X WHERE X eid 9999"
   557                         # return an empty result instead of raising UnknownEid
   559                         # return an empty result instead of raising UnknownEid
   558                         return empty_rset(rql, args)
   560                         return empty_rset(rql, args)
   559             rqlst = self._rql_cache[cachekey]
   561             rqlst = self._rql_cache[cachekey]
   560             self.cache_hit += 1
   562             self.cache_hit += 1
       
   563             statsd_c('cache_hit')
   561         except KeyError:
   564         except KeyError:
   562             self.cache_miss += 1
   565             self.cache_miss += 1
       
   566             statsd_c('cache_miss')
   563             rqlst = self.parse(rql)
   567             rqlst = self.parse(rql)
   564             try:
   568             try:
   565                 # compute solutions for rqlst and return named args in query
   569                 # compute solutions for rqlst and return named args in query
   566                 # which are eids. Notice that if you may not need `eidkeys`, we
   570                 # which are eids. Notice that if you may not need `eidkeys`, we
   567                 # have to compute solutions anyway (kept as annotation on the
   571                 # have to compute solutions anyway (kept as annotation on the