diff --git a/arkindex/documents/api/elements.py b/arkindex/documents/api/elements.py index 0be67b421e25618b7b03a0e2b918e6d16ea63094..46590a74414fa998e56b22664fe4f1c4edf107d0 100644 --- a/arkindex/documents/api/elements.py +++ b/arkindex/documents/api/elements.py @@ -945,6 +945,7 @@ class ElementsListBase(CorpusACLMixin, DestroyModelMixin, ListAPIView): def filter_queryset(self, queryset): queryset = queryset \ .filter(self.get_filters()) \ + .select_related("worker_run") \ .prefetch_related(*self.get_prefetch()) \ .order_by(*self.get_order_by()) diff --git a/arkindex/documents/tests/test_children_elements.py b/arkindex/documents/tests/test_children_elements.py index 50cb778c54259c2c8035bea7d6c51861975298f9..1eeb278e71b8e8e91e13cc74bc0f9641c070bb37 100644 --- a/arkindex/documents/tests/test_children_elements.py +++ b/arkindex/documents/tests/test_children_elements.py @@ -303,7 +303,7 @@ class TestChildrenElements(FixtureAPITestCase): worker_run_child = Element.objects.create(name="bob", type=self.page.type, worker_run=self.worker_run, worker_version=self.worker_version, corpus=self.corpus) worker_run_child.add_parent(self.vol) - with self.assertNumQueries(6): + with self.assertNumQueries(5): response = self.client.get( reverse("api:elements-children", kwargs={"pk": str(self.vol.id)}), data={"worker_run": str(self.worker_run.id)} diff --git a/arkindex/sql_validation/list_elements.sql b/arkindex/sql_validation/list_elements.sql index 9d23eaa4b2445d297a72b24db9636033ca1b73fa..8ae34bce8562819eae9764f3cfda23183b51ed2d 100644 --- a/arkindex/sql_validation/list_elements.sql +++ b/arkindex/sql_validation/list_elements.sql @@ -28,8 +28,19 @@ SELECT "documents_element"."id", "documents_element"."polygon"::bytea, "documents_element"."rotation_angle", "documents_element"."mirrored", - "documents_element"."confidence" + "documents_element"."confidence", + "process_workerrun"."id", + "process_workerrun"."process_id", + "process_workerrun"."version_id", + "process_workerrun"."model_version_id", + "process_workerrun"."parents", + "process_workerrun"."configuration_id", + "process_workerrun"."summary", + "process_workerrun"."created", + "process_workerrun"."updated", + "process_workerrun"."has_results" FROM "documents_element" +LEFT OUTER JOIN "process_workerrun" ON ("documents_element"."worker_run_id" = "process_workerrun"."id") WHERE ("documents_element"."corpus_id" = '{corpus_id}'::uuid AND "documents_element"."corpus_id" = '{corpus_id}'::uuid) ORDER BY "documents_element"."name" ASC,