Skip to content

Commit 36eaffd

Browse files
authored
feat: DIA-2206: prefetch fields in data export (#7410)
1 parent af252e7 commit 36eaffd

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

label_studio/data_export/mixins.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ def _get_filtered_annotations_queryset(self, annotation_filter_options=None):
110110
return queryset
111111

112112
q = reduce(lambda x, y: x | y, q_list)
113-
return queryset.filter(q)
113+
annotations_qs = queryset.filter(q)
114+
115+
# prefetch reviews in LSE
116+
if hasattr(annotations_qs.model, 'reviews'):
117+
annotations_qs = annotations_qs.prefetch_related('reviews')
118+
119+
return annotations_qs
114120

115121
@staticmethod
116122
def _get_export_serializer_option(serialization_options):
@@ -144,6 +150,7 @@ def _get_export_serializer_option(serialization_options):
144150

145151
def get_task_queryset(self, ids, annotation_filter_options):
146152
annotations_qs = self._get_filtered_annotations_queryset(annotation_filter_options=annotation_filter_options)
153+
147154
return (
148155
Task.objects.filter(id__in=ids)
149156
.prefetch_related(
@@ -152,7 +159,7 @@ def get_task_queryset(self, ids, annotation_filter_options):
152159
queryset=annotations_qs,
153160
)
154161
)
155-
.prefetch_related('predictions', 'drafts')
162+
.prefetch_related('predictions', 'drafts', 'comment_authors', 'file_upload')
156163
)
157164

158165
def get_export_data(self, task_filter_options=None, annotation_filter_options=None, serialization_options=None):
@@ -272,10 +279,10 @@ def export_to_file(self, task_filter_options=None, annotation_filter_options=Non
272279
self.status = self.Status.COMPLETED
273280
self.save(update_fields=['status'])
274281

275-
except Exception:
282+
except Exception as e:
276283
self.status = self.Status.FAILED
277284
self.save(update_fields=['status'])
278-
logger.exception('Export was failed')
285+
logger.exception('Export was failed: %s', e)
279286
finally:
280287
self.finished_at = datetime.now()
281288
self.save(update_fields=['finished_at'])

0 commit comments

Comments
 (0)