Skip to content

Commit 2830338

Browse files
committed
refactor: apply optimizations again
so the slowness went to the main query due to tool's select_related not making MariaDB use the index... now with prefetch_related on both it seems pretty good
1 parent b843ebb commit 2830338

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

store/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ def tag_ids(self):
207207

208208
@cached_property
209209
def sorted_tags(self):
210-
return self.tags.order_by('-priority', 'id')
210+
# tags come sorted through its Meta ordering
211+
return self.tags.all()
211212

212213
@cached_property
213214
def reverting_batches(self):

store/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ class APIBatchView(BatchView):
4646

4747
class BatchesView(generics.ListAPIView):
4848
serializer_class = BatchSimpleSerializer
49-
queryset = Batch.objects.all().order_by('-ended')
49+
queryset = (
50+
Batch.objects
51+
.prefetch_related('tags', 'tool')
52+
.order_by('-ended')
53+
)
5054
template_name = 'store/batches.html'
5155
filter_fields = ('user',)
5256
filter_backends = (TaggingFilterBackend,)

0 commit comments

Comments
 (0)