diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bd769f56..358a82d3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changes - Change how extensions and fallback priorities interact ([#1192](../../pull/1192)) - Refactor reading the .large_image_config.yaml file on the girder client ([#1193](../../pull/1193)) +- Refactor of the which-folders-have-annotations pipeline ([#1194](../../pull/1194)) ## 1.22.2 diff --git a/girder_annotation/girder_large_image_annotation/rest/annotation.py b/girder_annotation/girder_large_image_annotation/rest/annotation.py index 18b70fa5e..92c0e542c 100644 --- a/girder_annotation/girder_large_image_annotation/rest/annotation.py +++ b/girder_annotation/girder_large_image_annotation/rest/annotation.py @@ -601,25 +601,24 @@ def getFolderAnnotations(self, id, recurse, user, limit=False, offset=False, sor ] if not user['admin'] else [] recursivePipeline = [ {'$match': {'_id': ObjectId(id)}}, - {'$facet': { - 'documents1': [{'$match': {'_id': ObjectId(id)}}], - 'documents2': [ - {'$graphLookup': { - 'from': 'folder', - 'startWith': '$_id', - 'connectFromField': '_id', - 'connectToField': 'parentId', - 'as': '__children' - }}, - {'$unwind': {'path': '$__children'}}, - {'$replaceRoot': {'newRoot': '$__children'}} - ] + {'$graphLookup': { + 'from': 'folder', + 'startWith': ObjectId(id), + 'connectFromField': '_id', + 'connectToField': 'parentId', + 'as': '__children', + }}, + {'$lookup': { + 'from': 'folder', + 'localField': '_id', + 'foreignField': '_id', + 'as': '__self', }}, {'$project': {'__children': {'$concatArrays': [ - '$documents1', '$documents2' + '$__self', '$__children' ]}}}, {'$unwind': {'path': '$__children'}}, - {'$replaceRoot': {'newRoot': '$__children'}} + {'$replaceRoot': {'newRoot': '$__children'}}, ] if recurse else [{'$match': {'_id': ObjectId(id)}}] # We are only finding anntoations that we can change the permissions