def states_analyzer(node, source, validated):
"""Return for example
{'states': {
'editable': 250, 'published': 16264, 'archived': 269, 'active': 3}
}
"""
if 'metadata_filter' in validated:
validated['metadata_filter'].pop('states', None)
objects = source(**validated)
index = find_catalog('dace')['object_states']
intersection = index.family.IF.intersection
object_ids = getattr(objects, 'ids', objects)
if isinstance(object_ids, (list, types.GeneratorType)):
object_ids = index.family.IF.Set(object_ids)
result = [(state_id, len(intersection(object_ids, oids)))
for state_id, oids in index._fwd_index.items()]
result = dict([(k, v) for k, v in result if v != 0])
return {'states': result}
评论列表
文章目录