core: added getEntitiesData which get cache data for several entities at once
This commit is contained in:
parent
5049bc0b47
commit
ec25ba82e1
1 changed files with 84 additions and 3 deletions
|
|
@ -636,6 +636,54 @@ class Memory(object):
|
|||
else:
|
||||
raise e
|
||||
|
||||
def _getEntitiesData(self, entities_jids, keys_list, profile_key):
|
||||
ret = self.getEntitiesData([jid.JID(jid_) for jid_ in entities_jids], keys_list, profile_key)
|
||||
return {jid_.full(): data for jid_, data in ret.iteritems()}
|
||||
|
||||
def getEntitiesData(self, entities_jids, keys_list=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get a list of cached values for several entities at once
|
||||
|
||||
@param entities_jids: jids of the entities, or empty list for all entities in cache
|
||||
@param keys_list (iterable,None): list of keys to get, None for everything
|
||||
@param profile_key: %(doc_profile_key)s
|
||||
@return: dict withs values for each key in keys_list.
|
||||
if there is no value of a given key, resulting dict will
|
||||
have nothing with that key nether
|
||||
if an entity doesn't exist in cache, it will not appear
|
||||
in resulting dict
|
||||
|
||||
@raise exceptions.UnknownEntityError: if entity is not in cache
|
||||
"""
|
||||
def fillEntityData(entity_cache_data):
|
||||
entity_data = {}
|
||||
if keys_list is None:
|
||||
entity_data = entity_cache_data
|
||||
else:
|
||||
for key in keys_list:
|
||||
try:
|
||||
entity_data[key] = entity_cache_data[key]
|
||||
except KeyError:
|
||||
continue
|
||||
return entity_data
|
||||
|
||||
profile_cache = self._getProfileCache(profile_key)
|
||||
ret_data = {}
|
||||
if entities_jids:
|
||||
for entity in entities_jids:
|
||||
try:
|
||||
entity_cache_data = profile_cache[entity.userhostJID()][entity.resource]
|
||||
except KeyError:
|
||||
continue
|
||||
ret_data[entity.full()] = fillEntityData(entity_cache_data, keys_list)
|
||||
else:
|
||||
for bare_jid, data in profile_cache.iteritems():
|
||||
for resource, entity_cache_data in data.iteritems():
|
||||
full_jid = copy.copy(bare_jid)
|
||||
full_jid.resource = resource
|
||||
ret_data[full_jid] = fillEntityData(entity_cache_data)
|
||||
|
||||
return ret_data
|
||||
|
||||
def getEntityData(self, entity_jid, keys_list=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get a list of cached values for entity
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue