Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3514,15 +3514,3 @@ class Meta:
ObjectList(panels_statistics, heading=_("Complete Statistics")),
]
)

def get_queryset(self, request):
"""QuerySet otimizado com select_related e prefetch_related"""
return self.objects.select_related(
'journal',
'issue',
'journal__official',
).prefetch_related(
'doi',
'titles',
'languages',
)
12 changes: 12 additions & 0 deletions article/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ class ArticlePeerReviewStatsSnippetViewSet(SnippetViewSet):
ordering = ["-updated"]
list_per_page = 25

def get_queryset(self):
"""QuerySet otimizado com select_related e prefetch_related"""
return super().get_queryset().select_related(
'journal',
'issue',
'journal__official',
).prefetch_related(
'doi',
'titles',
'languages',
Comment on lines +231 to +233
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_queryset() is prefetching the M2M relations (doi, titles, languages) for every page of the listing. This adds extra queries and can pull additional rows even though these relations aren’t used in list_display/filters here; consider dropping these prefetch_related() calls (or limiting them to what the list actually needs) to keep the admin listing lighter.

Suggested change
'doi',
'titles',
'languages',
'titles',

Copilot uses AI. Check for mistakes.
)


class ArticleSnippetViewSetGroup(SnippetViewSetGroup):
menu_label = _("Articles")
Expand Down
4 changes: 2 additions & 2 deletions core/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ class LicenseViewSet(SnippetViewSet):
list_export = ("license_type", "version")
inspect_view_enabled = True

def get_queryset(self, request):
return super().get_queryset(request).select_related("creator")
def get_queryset(self):
return super().get_queryset().select_related("creator")
4 changes: 2 additions & 2 deletions issue/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ class IssueAdminSnippetViewSet(SnippetViewSet):
"year",
)

def get_queryset(self, request):
def get_queryset(self):
# Base queryset com otimizações
qs = Issue.objects.select_related(
"journal",
"creator",
"updated_by",
)

user = request.user
user = self.request.user

# Verificação de autenticação
if not user.is_authenticated:
Expand Down
18 changes: 9 additions & 9 deletions journal/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class FilteredJournalQuerysetMixin:
"contact_location__country__name",
)

def get_queryset(self, request):
def get_queryset(self):
qs = (
models.Journal.objects
# ForeignKey relationships - use select_related for forward ForeignKey lookups
Expand Down Expand Up @@ -246,7 +246,7 @@ def get_queryset(self, request):
"scielojournal_set__collection",
)
)
user = request.user
user = self.request.user
if not user.is_authenticated:
return qs.none()

Expand Down Expand Up @@ -328,14 +328,14 @@ class JournalAdminOnlySnippetViewSet(FilteredJournalQuerysetMixin, SnippetViewSe
exclude_from_explorer = False
list_per_page = 20

def get_queryset(self, request):
def get_queryset(self):
# Only allow superusers to access this viewset
user = request.user
user = self.request.user
if not user.is_authenticated or not user.is_superuser:
return models.Journal.objects.none()

# For superusers, return all journals with optimizations
return super().get_queryset(request)
return super().get_queryset()


class SciELOJournalCreateView(CreateView):
Expand Down Expand Up @@ -375,8 +375,8 @@ class SciELOJournalAdminViewSet(SnippetViewSet):
"issn_scielo",
)

def get_queryset(self, request):
user = request.user
def get_queryset(self):
user = self.request.user
if user.is_superuser:
return models.SciELOJournal.objects.select_related("journal", "collection")

Expand Down Expand Up @@ -506,11 +506,11 @@ class CrossmarkPolicyAdmin(SnippetViewSet):
"journal__title",
)

def get_queryset(self, request):
def get_queryset(self):
qs = models.CrossmarkPolicy.objects.select_related(
"journal",
)
user = request.user
user = self.request.user
if not user.is_authenticated:
return qs.none()

Expand Down
4 changes: 2 additions & 2 deletions location/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class LocationAdmin(SnippetViewSet):
)
export_filename = "locations"

def get_queryset(self, request):
return super().get_queryset(request).select_related(
def get_queryset(self):
return super().get_queryset().select_related(
"country", "state", "city", "creator",
)

Expand Down
16 changes: 8 additions & 8 deletions thematic_areas/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class GenericThematicAreaAdmin(SnippetViewSet):
)
export_filename = "generic_thematic_areas"

def get_queryset(self, request):
return super().get_queryset(request).select_related("creator")
def get_queryset(self):
return super().get_queryset().select_related("creator")


class GenericThematicAreaFileAdmin(SnippetViewSet):
Expand All @@ -90,8 +90,8 @@ class GenericThematicAreaFileAdmin(SnippetViewSet):
list_filter = ("is_valid",)
search_fields = ("attachment__title",)

def get_queryset(self, request):
return super().get_queryset(request).select_related("creator")
def get_queryset(self):
return super().get_queryset().select_related("creator")


class GenericThematicAreaAdminGroup(SnippetViewSetGroup):
Expand Down Expand Up @@ -165,8 +165,8 @@ class ThematicAreaAdmin(SnippetViewSet):
)
export_filename = "thematic_areas"

def get_queryset(self, request):
return super().get_queryset(request).select_related("creator")
def get_queryset(self):
return super().get_queryset().select_related("creator")


class ThematicAreaFileAdmin(SnippetViewSet):
Expand All @@ -189,8 +189,8 @@ class ThematicAreaFileAdmin(SnippetViewSet):
list_filter = ("is_valid",)
search_fields = ("attachment__title",)

def get_queryset(self, request):
return super().get_queryset(request).select_related("creator")
def get_queryset(self):
return super().get_queryset().select_related("creator")


class ThematicAreaAdminGroup(SnippetViewSetGroup):
Expand Down
Loading