From 43f7e218a65d73438545719f247db1488868639a Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Wed, 27 Mar 2019 17:23:26 -0400 Subject: [PATCH] Loading images from large datasets #152 --- app/api/annotator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/api/annotator.py b/app/api/annotator.py index bb2b76a2..e096adc4 100644 --- a/app/api/annotator.py +++ b/app/api/annotator.py @@ -127,11 +127,11 @@ def get(self, image_id): categories = CategoryModel.objects(deleted=False).in_bulk(dataset.categories).items() + # Get next and previous image - images = list(ImageModel.objects(dataset_id=dataset.id, deleted=False).order_by('file_name').all()) - image_index = images.index(image) - image_previous = None if image_index - 1 < 0 else images[image_index - 1].id - image_next = None if image_index + 1 == len(images) else images[image_index + 1].id + images = ImageModel.objects(dataset_id=dataset.id, deleted=False) + pre = images.filter(file_name__lt=image.file_name).order_by('-file_name').first() + nex = images.filter(file_name__gt=image.file_name).order_by('file_name').first() preferences = {} if not Config.LOGIN_DISABLED: @@ -149,8 +149,8 @@ def get(self, image_id): } } - data['image']['previous'] = image_previous - data['image']['next'] = image_next + data['image']['previous'] = pre.id if pre else None + data['image']['next'] = nex.id if nex else None for category in categories: category = query_util.fix_ids(category[1])