From 7bbb26b1e7305fd4c69ea8a7ec83feaa29fa1328 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Wed, 7 Jun 2023 11:33:41 -0400 Subject: [PATCH] Another refactor of the which-folders-have-annotations pipeline We are trying to keep performance and broad compatibility. --- CHANGELOG.md | 1 + .../rest/annotation.py | 29 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) 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