server/repository.py
changeset 9663 f512d72a1dc4
parent 9662 f13ae1fea212
child 9664 5ef5494b6b0b
equal deleted inserted replaced
9662:f13ae1fea212 9663:f512d72a1dc4
   969 
   969 
   970     # data sources handling ###################################################
   970     # data sources handling ###################################################
   971     # * correspondance between eid and (type, source)
   971     # * correspondance between eid and (type, source)
   972     # * correspondance between eid and local id (i.e. specific to a given source)
   972     # * correspondance between eid and local id (i.e. specific to a given source)
   973 
   973 
   974     def type_and_source_from_eid(self, eid, session=None):
   974     def type_and_source_from_eid(self, eid, session):
   975         """return a tuple `(type, extid, actual source uri)` for the entity of
   975         """return a tuple `(type, extid, actual source uri)` for the entity of
   976         the given `eid`
   976         the given `eid`
   977         """
   977         """
   978         try:
   978         try:
   979             eid = int(eid)
   979             eid = int(eid)
   980         except ValueError:
   980         except ValueError:
   981             raise UnknownEid(eid)
   981             raise UnknownEid(eid)
   982         try:
   982         try:
   983             return self._type_source_cache[eid]
   983             return self._type_source_cache[eid]
   984         except KeyError:
   984         except KeyError:
   985             if session is None:
   985             etype, extid, auri = self.system_source.eid_type_source(session,
   986                 session = self.internal_session()
   986                                                                     eid)
   987                 free_cnxset = True
       
   988             else:
       
   989                 free_cnxset = False
       
   990             try:
       
   991                 etype, extid, auri = self.system_source.eid_type_source(
       
   992                     session, eid)
       
   993             finally:
       
   994                 if free_cnxset:
       
   995                     session.free_cnxset()
       
   996             self._type_source_cache[eid] = (etype, extid, auri)
   987             self._type_source_cache[eid] = (etype, extid, auri)
   997             return etype, extid, auri
   988             return etype, extid, auri
   998 
   989 
   999     def clear_caches(self, eids):
   990     def clear_caches(self, eids):
  1000         etcache = self._type_source_cache
   991         etcache = self._type_source_cache
  1008             except KeyError:
   999             except KeyError:
  1009                 etype = None
  1000                 etype = None
  1010             rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None)
  1001             rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None)
  1011             self.system_source.clear_eid_cache(eid, etype)
  1002             self.system_source.clear_eid_cache(eid, etype)
  1012 
  1003 
  1013     def type_from_eid(self, eid, session=None):
  1004     def type_from_eid(self, eid, session):
  1014         """return the type of the entity with id <eid>"""
  1005         """return the type of the entity with id <eid>"""
  1015         return self.type_and_source_from_eid(eid, session)[0]
  1006         return self.type_and_source_from_eid(eid, session)[0]
  1016 
  1007 
  1017     def querier_cache_key(self, session, rql, args, eidkeys):
  1008     def querier_cache_key(self, session, rql, args, eidkeys):
  1018         cachekey = [rql]
  1009         cachekey = [rql]