Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions api/dao/containerutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

CONT_TYPES = ['acquisition', 'analysis', 'collection', 'group', 'project', 'session']
SINGULAR_TO_PLURAL = {
'acquisition': 'acquisitions',
'analysis': 'analyses',
'collection': 'collections',
'device': 'devices',
'group': 'groups',
'job': 'jobs',
'project': 'projects',
'session': 'sessions',
'acquisition': 'acquisitions',
'collection': 'collections',
'analysis': 'analyses',
'user': 'users',
}
PLURAL_TO_SINGULAR = {p: s for s, p in SINGULAR_TO_PLURAL.iteritems()}

Expand Down
15 changes: 13 additions & 2 deletions api/handlers/containerhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ def handle_origin(self, result):
# Join from database if we haven't for this origin before
if j_type != 'unknown' and result['join-origin'][j_type].get(j_id, None) is None:
# Initial join
join_doc = config.db[j_type + 's'].find_one({'_id': j_id_b})
j_types = containerutil.pluralize(j_type)
join_doc = config.db[j_types].find_one({'_id': j_id_b})

# Join in gear name on the job doc if requested
if join_gear_name and j_type == 'job':
if join_doc is not None and join_gear_name and j_type == 'job':

gear_id = join_doc['gear_id']
gear_name = None
Expand Down Expand Up @@ -267,6 +268,16 @@ def get_jobs(self, cid):
cont_array = [containerutil.ContainerReference('analysis', cid) for cid in id_array]
results += Queue.search(cont_array, states=states, tags=tags)

# Stateful closure to remove search duplicates
# Eventually, this code should not call Queue.search and should instead do its own work.
def match_ids(x):
should_add = str(x['_id']) in match_ids.unique_job_ids
match_ids.unique_job_ids.add(str(x['_id']))
return should_add

match_ids.unique_job_ids = set()
results = filter(match_ids, results)

# Ensure job uniqueness
seen_jobs = []
seen_gears = []
Expand Down