178 self.system_source = self.get_source('native', 'system', |
178 self.system_source = self.get_source('native', 'system', |
179 config.system_source_config.copy()) |
179 config.system_source_config.copy()) |
180 self.sources_by_uri = {'system': self.system_source} |
180 self.sources_by_uri = {'system': self.system_source} |
181 # querier helper, need to be created after sources initialization |
181 # querier helper, need to be created after sources initialization |
182 self.querier = querier.QuerierHelper(self, self.schema) |
182 self.querier = querier.QuerierHelper(self, self.schema) |
183 # cache eid -> (type, extid, actual source) |
183 # cache eid -> (type, extid) |
184 self._type_source_cache = {} |
184 self._type_extid_cache = {} |
185 # cache extid -> eid |
185 # cache extid -> eid |
186 # open some connection sets |
186 # open some connection sets |
187 if config.init_cnxset_pool: |
187 if config.init_cnxset_pool: |
188 self.init_cnxset_pool() |
188 self.init_cnxset_pool() |
189 # the hooks manager |
189 # the hooks manager |
709 except KeyError: |
709 except KeyError: |
710 raise BadConnectionId('No such session %s' % sessionid) |
710 raise BadConnectionId('No such session %s' % sessionid) |
711 return session |
711 return session |
712 |
712 |
713 # data sources handling ################################################### |
713 # data sources handling ################################################### |
714 # * correspondance between eid and (type, source) |
714 # * correspondance between eid and type |
715 # * correspondance between eid and local id (i.e. specific to a given source) |
715 # * correspondance between eid and local id (i.e. specific to a given source) |
716 |
716 |
717 def type_and_source_from_eid(self, eid, cnx): |
717 def clear_caches(self, eids): |
718 """return a tuple `(type, extid, actual source uri)` for the entity of |
718 etcache = self._type_extid_cache |
719 the given `eid` |
719 rqlcache = self.querier._rql_cache |
720 """ |
720 for eid in eids: |
|
721 try: |
|
722 etype, extid = etcache.pop(int(eid)) # may be a string in some cases |
|
723 rqlcache.pop(('%s X WHERE X eid %s' % (etype, eid),), None) |
|
724 except KeyError: |
|
725 etype = None |
|
726 rqlcache.pop(('Any X WHERE X eid %s' % eid,), None) |
|
727 self.system_source.clear_eid_cache(eid, etype) |
|
728 |
|
729 def type_and_extid_from_eid(self, eid, cnx): |
|
730 """Return the type and extid of the entity with id `eid`.""" |
721 try: |
731 try: |
722 eid = int(eid) |
732 eid = int(eid) |
723 except ValueError: |
733 except ValueError: |
724 raise UnknownEid(eid) |
734 raise UnknownEid(eid) |
725 try: |
735 try: |
726 return self._type_source_cache[eid] |
736 return self._type_extid_cache[eid] |
727 except KeyError: |
737 except KeyError: |
728 etype, extid, auri = self.system_source.eid_type_source(cnx, eid) |
738 etype, extid = self.system_source.eid_type_extid(cnx, eid) |
729 self._type_source_cache[eid] = (etype, extid, auri) |
739 self._type_extid_cache[eid] = (etype, extid) |
730 return etype, extid, auri |
740 return etype, extid |
731 |
|
732 def clear_caches(self, eids): |
|
733 etcache = self._type_source_cache |
|
734 rqlcache = self.querier._rql_cache |
|
735 for eid in eids: |
|
736 try: |
|
737 etype, extid, auri = etcache.pop(int(eid)) # may be a string in some cases |
|
738 rqlcache.pop(('%s X WHERE X eid %s' % (etype, eid),), None) |
|
739 except KeyError: |
|
740 etype = None |
|
741 rqlcache.pop(('Any X WHERE X eid %s' % eid,), None) |
|
742 self.system_source.clear_eid_cache(eid, etype) |
|
743 |
741 |
744 def type_from_eid(self, eid, cnx): |
742 def type_from_eid(self, eid, cnx): |
745 """return the type of the entity with id <eid>""" |
743 """Return the type of the entity with id `eid`""" |
746 return self.type_and_source_from_eid(eid, cnx)[0] |
744 return self.type_and_extid_from_eid(eid, cnx)[0] |
747 |
745 |
748 def querier_cache_key(self, cnx, rql, args, eidkeys): |
746 def querier_cache_key(self, cnx, rql, args, eidkeys): |
749 cachekey = [rql] |
747 cachekey = [rql] |
750 for key in sorted(eidkeys): |
748 for key in sorted(eidkeys): |
751 try: |
749 try: |
813 cnx.set_entity_cache(entity) |
811 cnx.set_entity_cache(entity) |
814 if source.uri == 'system': |
812 if source.uri == 'system': |
815 extid = None |
813 extid = None |
816 else: |
814 else: |
817 extid = source.get_extid(entity) |
815 extid = source.get_extid(entity) |
818 self._type_source_cache[entity.eid] = (entity.cw_etype, extid, source.uri) |
816 self._type_extid_cache[entity.eid] = (entity.cw_etype, extid) |
819 return extid |
817 return extid |
820 |
818 |
821 def glob_add_entity(self, cnx, edited): |
819 def glob_add_entity(self, cnx, edited): |
822 """add an entity to the repository |
820 """add an entity to the repository |
823 |
821 |