server/repository.py
changeset 9800 029f9eafe574
parent 9774 b7b71be569cf
child 9885 9f546848ba48
equal deleted inserted replaced
9799:5362310d46da 9800:029f9eafe574
   939 
   939 
   940     # data sources handling ###################################################
   940     # data sources handling ###################################################
   941     # * correspondance between eid and (type, source)
   941     # * correspondance between eid and (type, source)
   942     # * correspondance between eid and local id (i.e. specific to a given source)
   942     # * correspondance between eid and local id (i.e. specific to a given source)
   943 
   943 
   944     def type_and_source_from_eid(self, eid, session):
   944     def type_and_source_from_eid(self, eid, cnx):
   945         """return a tuple `(type, extid, actual source uri)` for the entity of
   945         """return a tuple `(type, extid, actual source uri)` for the entity of
   946         the given `eid`
   946         the given `eid`
   947         """
   947         """
   948         try:
   948         try:
   949             eid = int(eid)
   949             eid = int(eid)
   950         except ValueError:
   950         except ValueError:
   951             raise UnknownEid(eid)
   951             raise UnknownEid(eid)
   952         try:
   952         try:
   953             return self._type_source_cache[eid]
   953             return self._type_source_cache[eid]
   954         except KeyError:
   954         except KeyError:
   955             etype, extid, auri = self.system_source.eid_type_source(session,
   955             etype, extid, auri = self.system_source.eid_type_source(cnx, eid)
   956                                                                     eid)
       
   957             self._type_source_cache[eid] = (etype, extid, auri)
   956             self._type_source_cache[eid] = (etype, extid, auri)
   958             return etype, extid, auri
   957             return etype, extid, auri
   959 
   958 
   960     def clear_caches(self, eids):
   959     def clear_caches(self, eids):
   961         etcache = self._type_source_cache
   960         etcache = self._type_source_cache
   969             except KeyError:
   968             except KeyError:
   970                 etype = None
   969                 etype = None
   971             rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None)
   970             rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None)
   972             self.system_source.clear_eid_cache(eid, etype)
   971             self.system_source.clear_eid_cache(eid, etype)
   973 
   972 
   974     def type_from_eid(self, eid, session):
   973     def type_from_eid(self, eid, cnx):
   975         """return the type of the entity with id <eid>"""
   974         """return the type of the entity with id <eid>"""
   976         return self.type_and_source_from_eid(eid, session)[0]
   975         return self.type_and_source_from_eid(eid, cnx)[0]
   977 
   976 
   978     def querier_cache_key(self, session, rql, args, eidkeys):
   977     def querier_cache_key(self, session, rql, args, eidkeys):
   979         cachekey = [rql]
   978         cachekey = [rql]
   980         for key in sorted(eidkeys):
   979         for key in sorted(eidkeys):
   981             try:
   980             try: