Skip to content

Commit 80b1e56

Browse files
authored
Fix display set index with duplicate order (#4097)
This is not efficient, the original implementation iterated over all of the display sets in the reader study and this keeps the same just to fix the bug. It can probably be replaced with a window function. Closes #4095
1 parent 10edff5 commit 80b1e56

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

app/grandchallenge/reader_studies/models.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,7 @@ def description(self) -> str:
987987

988988
@property
989989
def standard_index(self) -> int:
990-
return len(
991-
[
992-
x
993-
for x in self.reader_study.display_sets.all()
994-
if x.order < self.order
995-
]
996-
)
990+
return [*self.reader_study.display_sets.all()].index(self)
997991

998992
@property
999993
def update_url(self):

app/grandchallenge/reader_studies/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,10 @@ class DisplaySetViewSet(
10221022
DisplaySet.objects.all()
10231023
.select_related("reader_study__hanging_protocol")
10241024
.prefetch_related(
1025-
"values__image", "values__interface", "reader_study__display_sets"
1025+
"values__image",
1026+
"values__interface",
1027+
"reader_study__display_sets",
1028+
"reader_study__optional_hanging_protocols",
10261029
)
10271030
)
10281031
permission_classes = [DjangoObjectPermissions]

app/tests/reader_studies_tests/test_api.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,31 @@ def test_display_set_index(client):
20932093
]
20942094

20952095

2096+
@pytest.mark.django_db
2097+
def test_display_set_index_with_duplicate_order(
2098+
client, django_assert_num_queries
2099+
):
2100+
reader_study = ReaderStudyFactory()
2101+
user = UserFactory()
2102+
reader_study.add_reader(user)
2103+
2104+
ds1, ds2, *_ = DisplaySetFactory.create_batch(3, reader_study=reader_study)
2105+
2106+
ds2.order = ds1.order
2107+
ds2.save()
2108+
2109+
with django_assert_num_queries(34):
2110+
response = get_view_for_user(
2111+
viewname="api:reader-studies-display-set-list",
2112+
data={"reader_study": str(reader_study.pk)},
2113+
user=user,
2114+
client=client,
2115+
method=client.get,
2116+
)
2117+
2118+
assert [x["index"] for x in response.json()["results"]] == [0, 1, 2]
2119+
2120+
20962121
@pytest.mark.django_db
20972122
def test_total_edit_duration(client):
20982123
rs = ReaderStudyFactory(allow_answer_modification=True)

0 commit comments

Comments
 (0)