Skip to content

Commit

Permalink
Optimize Annotator API Query (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
geminixiang committed Feb 1, 2022
1 parent 2ed7355 commit 11a4838
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions backend/webserver/api/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,21 @@ def get(self, image_id):
data['image']['previous'] = pre.id if pre else None
data['image']['next'] = nex.id if nex else None

# Optimize query: query all annotation of specific image, and then categorize them according to the categories.
all_annotations = AnnotationModel.objects(image_id=image_id, deleted=False).exclude('events').all()

for category in categories:
category = query_util.fix_ids(category[1])

category_id = category.get('id')
annotations = AnnotationModel.objects(image_id=image_id, category_id=category_id, deleted=False)\
.exclude('events').all()

annotations = []
for annotation in all_annotations:
if annotation['category_id'] == category_id:
annotations.append(query_util.fix_ids(annotation))

category['show'] = True
category['visualize'] = False
category['annotations'] = [] if annotations is None else query_util.fix_ids(annotations)
category['annotations'] = [] if annotations is None else annotations
data.get('categories').append(category)

return data


0 comments on commit 11a4838

Please sign in to comment.