server/sources/native.py
changeset 7954 a3d3220669d6
parent 7922 d307c3817782
child 7967 c87b87b62f8f
equal deleted inserted replaced
7953:a37531c8a4a6 7954:a3d3220669d6
    44 import zipfile
    44 import zipfile
    45 import logging
    45 import logging
    46 import sys
    46 import sys
    47 
    47 
    48 from logilab.common.compat import any
    48 from logilab.common.compat import any
    49 from logilab.common.cache import Cache
       
    50 from logilab.common.decorators import cached, clear_cache
    49 from logilab.common.decorators import cached, clear_cache
    51 from logilab.common.configuration import Method
    50 from logilab.common.configuration import Method
    52 from logilab.common.shellutils import getlogin
    51 from logilab.common.shellutils import getlogin
    53 from logilab.database import get_db_helper, sqlgen
    52 from logilab.database import get_db_helper, sqlgen
    54 
    53 
    56 from yams.schema import role_name
    55 from yams.schema import role_name
    57 
    56 
    58 from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary,
    57 from cubicweb import (UnknownEid, AuthenticationError, ValidationError, Binary,
    59                       UniqueTogetherError)
    58                       UniqueTogetherError)
    60 from cubicweb import transaction as tx, server, neg_role
    59 from cubicweb import transaction as tx, server, neg_role
       
    60 from cubicweb.utils import QueryCache
    61 from cubicweb.schema import VIRTUAL_RTYPES
    61 from cubicweb.schema import VIRTUAL_RTYPES
    62 from cubicweb.cwconfig import CubicWebNoAppConfiguration
    62 from cubicweb.cwconfig import CubicWebNoAppConfiguration
    63 from cubicweb.server import hook
    63 from cubicweb.server import hook
    64 from cubicweb.server.utils import crypt_password, eschema_eid
    64 from cubicweb.server.utils import crypt_password, eschema_eid
    65 from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn
    65 from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn
   293         self._rql_sqlgen = self.sqlgen_class(self.schema, self.dbhelper,
   293         self._rql_sqlgen = self.sqlgen_class(self.schema, self.dbhelper,
   294                                              ATTR_MAP.copy())
   294                                              ATTR_MAP.copy())
   295         # full text index helper
   295         # full text index helper
   296         self.do_fti = not repo.config['delay-full-text-indexation']
   296         self.do_fti = not repo.config['delay-full-text-indexation']
   297         # sql queries cache
   297         # sql queries cache
   298         self._cache = Cache(repo.config['rql-cache-size'])
   298         self._cache = QueryCache(repo.config['rql-cache-size'])
   299         self._temp_table_data = {}
   299         self._temp_table_data = {}
   300         # we need a lock to protect eid attribution function (XXX, really?
   300         # we need a lock to protect eid attribution function (XXX, really?
   301         # explain)
   301         # explain)
   302         self._eid_cnx_lock = Lock()
   302         self._eid_cnx_lock = Lock()
   303         self._eid_creation_cnx = None
   303         self._eid_creation_cnx = None
   341         authentifier.source = self
   341         authentifier.source = self
   342         authentifier.set_schema(self.schema)
   342         authentifier.set_schema(self.schema)
   343 
   343 
   344     def reset_caches(self):
   344     def reset_caches(self):
   345         """method called during test to reset potential source caches"""
   345         """method called during test to reset potential source caches"""
   346         self._cache = Cache(self.repo.config['rql-cache-size'])
   346         self._cache = QueryCache(self.repo.config['rql-cache-size'])
   347 
   347 
   348     def clear_eid_cache(self, eid, etype):
   348     def clear_eid_cache(self, eid, etype):
   349         """clear potential caches for the given eid"""
   349         """clear potential caches for the given eid"""
   350         self._cache.pop('Any X WHERE X eid %s, X is %s' % (eid, etype), None)
   350         self._cache.pop('Any X WHERE X eid %s, X is %s' % (eid, etype), None)
   351         self._cache.pop('Any X WHERE X eid %s' % eid, None)
   351         self._cache.pop('Any X WHERE X eid %s' % eid, None)
   461         set_qdata(self.schema.rschema, rqlst, ())
   461         set_qdata(self.schema.rschema, rqlst, ())
   462         return rqlst
   462         return rqlst
   463 
   463 
   464     def set_schema(self, schema):
   464     def set_schema(self, schema):
   465         """set the instance'schema"""
   465         """set the instance'schema"""
   466         self._cache = Cache(self.repo.config['rql-cache-size'])
   466         self._cache = QueryCache(self.repo.config['rql-cache-size'])
   467         self.cache_hit, self.cache_miss, self.no_cache = 0, 0, 0
   467         self.cache_hit, self.cache_miss, self.no_cache = 0, 0, 0
   468         self.schema = schema
   468         self.schema = schema
   469         try:
   469         try:
   470             self._rql_sqlgen.schema = schema
   470             self._rql_sqlgen.schema = schema
   471         except AttributeError:
   471         except AttributeError: