server/sources/native.py
changeset 10477 ee21c559f94f
parent 10473 23a2fa8cb725
child 10550 d4bd28d5fca8
equal deleted inserted replaced
10476:62251bfdfd79 10477:ee21c559f94f
    58 from cubicweb.server.rqlannotation import set_qdata
    58 from cubicweb.server.rqlannotation import set_qdata
    59 from cubicweb.server.hook import CleanupDeletedEidsCacheOp
    59 from cubicweb.server.hook import CleanupDeletedEidsCacheOp
    60 from cubicweb.server.edition import EditedEntity
    60 from cubicweb.server.edition import EditedEntity
    61 from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results
    61 from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results
    62 from cubicweb.server.sources.rql2sql import SQLGenerator
    62 from cubicweb.server.sources.rql2sql import SQLGenerator
       
    63 from cubicweb.statsd_logger import statsd_timeit
    63 
    64 
    64 
    65 
    65 ATTR_MAP = {}
    66 ATTR_MAP = {}
    66 NONSYSTEM_ETYPES = set()
    67 NONSYSTEM_ETYPES = set()
    67 NONSYSTEM_RELATIONS = set()
    68 NONSYSTEM_RELATIONS = set()
   374         """clear potential caches for the given eid"""
   375         """clear potential caches for the given eid"""
   375         self._cache.pop('Any X WHERE X eid %s, X is %s' % (eid, etype), None)
   376         self._cache.pop('Any X WHERE X eid %s, X is %s' % (eid, etype), None)
   376         self._cache.pop('Any X WHERE X eid %s' % eid, None)
   377         self._cache.pop('Any X WHERE X eid %s' % eid, None)
   377         self._cache.pop('Any %s' % eid, None)
   378         self._cache.pop('Any %s' % eid, None)
   378 
   379 
       
   380     @statsd_timeit
   379     def sqlexec(self, cnx, sql, args=None):
   381     def sqlexec(self, cnx, sql, args=None):
   380         """execute the query and return its result"""
   382         """execute the query and return its result"""
   381         return self.process_result(self.doexec(cnx, sql, args))
   383         return self.process_result(self.doexec(cnx, sql, args))
   382 
   384 
   383     def init_creating(self, cnxset=None):
   385     def init_creating(self, cnxset=None):
   478         except KeyError:
   480         except KeyError:
   479             raise Exception('no custom storage set for %s.%s' % (etype, attr))
   481             raise Exception('no custom storage set for %s.%s' % (etype, attr))
   480 
   482 
   481     # ISource interface #######################################################
   483     # ISource interface #######################################################
   482 
   484 
       
   485     @statsd_timeit
   483     def compile_rql(self, rql, sols):
   486     def compile_rql(self, rql, sols):
   484         rqlst = self.repo.vreg.rqlhelper.parse(rql)
   487         rqlst = self.repo.vreg.rqlhelper.parse(rql)
   485         rqlst.restricted_vars = ()
   488         rqlst.restricted_vars = ()
   486         rqlst.children[0].solutions = sols
   489         rqlst.children[0].solutions = sols
   487         self.repo.querier.sqlgen_annotate(rqlst)
   490         self.repo.querier.sqlgen_annotate(rqlst)
   515             return not rtype in NONSYSTEM_RELATIONS
   518             return not rtype in NONSYSTEM_RELATIONS
   516         # due to current multi-sources implementation, the system source
   519         # due to current multi-sources implementation, the system source
   517         # can't claim not supporting a relation
   520         # can't claim not supporting a relation
   518         return True #not rtype == 'content_for'
   521         return True #not rtype == 'content_for'
   519 
   522 
       
   523     @statsd_timeit
   520     def authenticate(self, cnx, login, **kwargs):
   524     def authenticate(self, cnx, login, **kwargs):
   521         """return CWUser eid for the given login and other authentication
   525         """return CWUser eid for the given login and other authentication
   522         information found in kwargs, else raise `AuthenticationError`
   526         information found in kwargs, else raise `AuthenticationError`
   523         """
   527         """
   524         for authentifier in self.authentifiers:
   528         for authentifier in self.authentifiers:
   685         else:
   689         else:
   686             attrs = {'eid_from': subject, 'eid_to': object}
   690             attrs = {'eid_from': subject, 'eid_to': object}
   687             sql = self.sqlgen.delete('%s_relation' % rtype, attrs)
   691             sql = self.sqlgen.delete('%s_relation' % rtype, attrs)
   688         self.doexec(cnx, sql, attrs)
   692         self.doexec(cnx, sql, attrs)
   689 
   693 
       
   694     @statsd_timeit
   690     def doexec(self, cnx, query, args=None, rollback=True):
   695     def doexec(self, cnx, query, args=None, rollback=True):
   691         """Execute a query.
   696         """Execute a query.
   692         it's a function just so that it shows up in profiling
   697         it's a function just so that it shows up in profiling
   693         """
   698         """
   694         cursor = cnx.cnxset.cu
   699         cursor = cnx.cnxset.cu
   744                         # sqlite3 (old)
   749                         # sqlite3 (old)
   745                         raise ViolatedConstraint(cnx, cstrname=mo.group(1))
   750                         raise ViolatedConstraint(cnx, cstrname=mo.group(1))
   746             raise
   751             raise
   747         return cursor
   752         return cursor
   748 
   753 
       
   754     @statsd_timeit
   749     def doexecmany(self, cnx, query, args):
   755     def doexecmany(self, cnx, query, args):
   750         """Execute a query.
   756         """Execute a query.
   751         it's a function just so that it shows up in profiling
   757         it's a function just so that it shows up in profiling
   752         """
   758         """
   753         if server.DEBUG & server.DBG_SQL:
   759         if server.DEBUG & server.DBG_SQL: