server/repository.py
changeset 8748 f5027f8d2478
parent 8699 864ffd247d70
child 8771 519629422391
equal deleted inserted replaced
8747:c0d4244e5abc 8748:f5027f8d2478
    48 
    48 
    49 from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, QueryError,
    49 from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, QueryError,
    50                       UnknownEid, AuthenticationError, ExecutionError,
    50                       UnknownEid, AuthenticationError, ExecutionError,
    51                       ETypeNotSupportedBySources, MultiSourcesError,
    51                       ETypeNotSupportedBySources, MultiSourcesError,
    52                       BadConnectionId, Unauthorized, ValidationError,
    52                       BadConnectionId, Unauthorized, ValidationError,
    53                       RepositoryError, UniqueTogetherError, typed_eid, onevent)
    53                       RepositoryError, UniqueTogetherError, onevent)
    54 from cubicweb import cwvreg, schema, server
    54 from cubicweb import cwvreg, schema, server
    55 from cubicweb.server import ShuttingDown, utils, hook, pool, querier, sources
    55 from cubicweb.server import ShuttingDown, utils, hook, pool, querier, sources
    56 from cubicweb.server.session import Session, InternalSession, InternalManager
    56 from cubicweb.server.session import Session, InternalSession, InternalManager
    57 from cubicweb.server.ssplanner import EditedEntity
    57 from cubicweb.server.ssplanner import EditedEntity
    58 
    58 
  1016     def type_and_source_from_eid(self, eid, session=None):
  1016     def type_and_source_from_eid(self, eid, session=None):
  1017         """return a tuple `(type, physical source uri, extid, actual source
  1017         """return a tuple `(type, physical source uri, extid, actual source
  1018         uri)` for the entity of the given `eid`
  1018         uri)` for the entity of the given `eid`
  1019         """
  1019         """
  1020         try:
  1020         try:
  1021             eid = typed_eid(eid)
  1021             eid = int(eid)
  1022         except ValueError:
  1022         except ValueError:
  1023             raise UnknownEid(eid)
  1023             raise UnknownEid(eid)
  1024         try:
  1024         try:
  1025             return self._type_source_cache[eid]
  1025             return self._type_source_cache[eid]
  1026         except KeyError:
  1026         except KeyError:
  1044         etcache = self._type_source_cache
  1044         etcache = self._type_source_cache
  1045         extidcache = self._extid_cache
  1045         extidcache = self._extid_cache
  1046         rqlcache = self.querier._rql_cache
  1046         rqlcache = self.querier._rql_cache
  1047         for eid in eids:
  1047         for eid in eids:
  1048             try:
  1048             try:
  1049                 etype, uri, extid, auri = etcache.pop(typed_eid(eid)) # may be a string in some cases
  1049                 etype, uri, extid, auri = etcache.pop(int(eid)) # may be a string in some cases
  1050                 rqlcache.pop( ('%s X WHERE X eid %s' % (etype, eid),), None)
  1050                 rqlcache.pop( ('%s X WHERE X eid %s' % (etype, eid),), None)
  1051                 extidcache.pop((extid, uri), None)
  1051                 extidcache.pop((extid, uri), None)
  1052             except KeyError:
  1052             except KeyError:
  1053                 etype = None
  1053                 etype = None
  1054             rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None)
  1054             rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None)
  1073             except TypeError:
  1073             except TypeError:
  1074                 raise QueryError('bad cache key %s (value: %r)' % (
  1074                 raise QueryError('bad cache key %s (value: %r)' % (
  1075                     key, args[key]))
  1075                     key, args[key]))
  1076             cachekey.append(etype)
  1076             cachekey.append(etype)
  1077             # ensure eid is correctly typed in args
  1077             # ensure eid is correctly typed in args
  1078             args[key] = typed_eid(args[key])
  1078             args[key] = int(args[key])
  1079         return tuple(cachekey)
  1079         return tuple(cachekey)
  1080 
  1080 
  1081     def eid2extid(self, source, eid, session=None):
  1081     def eid2extid(self, source, eid, session=None):
  1082         """get local id from an eid"""
  1082         """get local id from an eid"""
  1083         etype, uri, extid, _ = self.type_and_source_from_eid(eid, session)
  1083         etype, uri, extid, _ = self.type_and_source_from_eid(eid, session)