Take pagination into account when listing tasks for all shots.
This is a stop-gap measure; we probably want to abstract this away into something more reusable. Better to do that after switching to Python 3, though.
This commit is contained in:
@@ -138,6 +138,8 @@ class ShotAssetManager(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from pillar.web.utils import last_page_index
|
||||||
|
|
||||||
api = pillar_api()
|
api = pillar_api()
|
||||||
|
|
||||||
id_to_shot = {}
|
id_to_shot = {}
|
||||||
@@ -147,21 +149,30 @@ class ShotAssetManager(object):
|
|||||||
id_to_shot[shot_id] = shot
|
id_to_shot[shot_id] = shot
|
||||||
shot_id_to_tasks[shot_id] = collections.defaultdict(set)
|
shot_id_to_tasks[shot_id] = collections.defaultdict(set)
|
||||||
|
|
||||||
found = pillarsdk.Node.all({
|
page_idx = 1
|
||||||
'where': {
|
while True:
|
||||||
'node_type': node_type_task['name'],
|
found = pillarsdk.Node.all({
|
||||||
'parent': {'$in': list(id_to_shot.keys())},
|
'where': {
|
||||||
}
|
'node_type': node_type_task['name'],
|
||||||
}, api=api)
|
'parent': {'$in': list(id_to_shot.keys())},
|
||||||
|
},
|
||||||
|
'page': page_idx,
|
||||||
|
}, api=api)
|
||||||
|
|
||||||
known = set(known_task_types) # for fast lookups
|
known = set(known_task_types) # for fast lookups
|
||||||
|
|
||||||
# Now put the tasks into the right spot.
|
# Put the tasks into the right spot.
|
||||||
for task in found['_items']:
|
for task in found['_items']:
|
||||||
task_type = task.properties.task_type
|
task_type = task.properties.task_type
|
||||||
if task_type not in known:
|
if task_type not in known:
|
||||||
task_type = None
|
task_type = None
|
||||||
shot_id_to_tasks[task.parent][task_type].add(task)
|
shot_id_to_tasks[task.parent][task_type].add(task)
|
||||||
|
|
||||||
|
# Keep looping over the pages. Result count can change between
|
||||||
|
# queries, so always recompute the last page index.
|
||||||
|
if page_idx >= last_page_index(found['_meta']):
|
||||||
|
break
|
||||||
|
page_idx += 1
|
||||||
|
|
||||||
return shot_id_to_tasks
|
return shot_id_to_tasks
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user