From a13be8707726511d17f4a11be3ed2b263f4a280b Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 28 Apr 2025 13:04:32 +0100 Subject: [PATCH] . --- atlas/tables.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/atlas/tables.py b/atlas/tables.py index 457a79ee..2a9af91e 100755 --- a/atlas/tables.py +++ b/atlas/tables.py @@ -22,12 +22,17 @@ from easy_thumbnails.files import get_thumbnailer from easy_thumbnails.exceptions import InvalidImageFormatError - - +from django.db.models import Prefetch class CaseTable(tables.Table): def __init__(self, data=None, *args, **kwargs): + # Optimize prefetching for casecollection_set + #case_collections_prefetch = Prefetch( + # "casecollection_set", + # queryset=CaseCollection.objects.select_related("author"), # Adjust fields as needed + #) + super().__init__( data.prefetch_related( "author", # Many-to-many or reverse relationship @@ -36,7 +41,9 @@ class CaseTable(tables.Table): "series__plane", # ForeignKey in the related model "series__images", # Reverse relationship "previous_case", # Prefetch the previous case relationship - #"next_case", # Prefetch the next case relationship + "next_case", # Prefetch the next case relationship + "casecollection_set", # Prefetch the case collection set + #case_collections_prefetch, # Optimized prefetch for collections ), *args, **kwargs,