Skip to content

Commit

Permalink
Merge pull request #1590 from girder/plottable-elements
Browse files Browse the repository at this point in the history
Add an index to speed up getting plottable data from annotation elements
  • Loading branch information
manthey authored Jul 29, 2024
2 parents 8a706f0 + 94ec077 commit 1e9a870
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Make the plottable data class threadsafe ([#1588](../../pull/1588))
- Speed up getting plottable data from items ([#1589](../../pull/1589))
- Add an index to speed up getting plottable data from annotation elements ([#1590](../../pull/1590))

## 1.29.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def initialize(self):
], {
'name': 'annotationGroupIdx',
}),
([
('annotationId', SortDir.ASCENDING),
('_version', SortDir.DESCENDING),
('_id', SortDir.ASCENDING),
], {
'name': 'annotationElementIdIdx',
}),
([
('created', SortDir.ASCENDING),
('_version', SortDir.ASCENDING),
Expand Down Expand Up @@ -159,6 +166,13 @@ def getElements(self, annotation, region=None):
annotation['annotation']['elements'] = list(self.yieldElements(
annotation, region, annotation['_elementQuery']))

def countElements(self, annotation):
query = {
'annotationId': annotation.get('_annotationId', annotation['_id']),
'_version': annotation['_version'],
}
return self.collection.count_documents(query)

def yieldElements(self, annotation, region=None, info=None, bbox=False): # noqa
"""
Given an annotation, fetch the elements from the database.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import itertools
import json
import math
import re
Expand Down Expand Up @@ -347,7 +346,7 @@ def isGeoJSON(annotation):

class PlottableItemData:
maxItems = 1000
maxAnnotationElements = 10000
maxAnnotationElements = 5000
maxDistinct = 20
allowedTypes = (str, bool, int, float)

Expand Down Expand Up @@ -878,11 +877,11 @@ def _getColumns(self):
if not self._sources or 'annotation' in self._sources:
self._collectColumns(columns, [annot], 'annotation', iid=iid)
# add annotation elements
if not self._sources or 'annotationelement' in self._sources:
elements = list(itertools.islice(Annotationelement().yieldElements(
annot, bbox=True), self.maxAnnotationElements))
self._collectColumns(
columns, elements, 'annotationelement', iid=iid, aid=str(annot['_id']))
if ((not self._sources or 'annotationelement' in self._sources) and
Annotationelement().countElements(annot) <= self.maxAnnotationElements):
for element in Annotationelement().yieldElements(annot, bbox=True):
self._collectColumns(
columns, [element], 'annotationelement', iid=iid, aid=str(annot['_id']))
# TODO: Add csv
for result in columns.values():
if len(result['distinct']) <= self.maxDistinct:
Expand Down

0 comments on commit 1e9a870

Please sign in to comment.