-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: admin perf optimization for course-discovery #4496
Conversation
7847892
to
85fd64b
Compare
63bd27e
to
811e8f6
Compare
Prefetch( | ||
'type__translations', | ||
queryset=ProgramTypeTranslation.objects.filter(language_code='en'), | ||
to_attr='prefetched_translations' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Prefetch helpful? I don't see how the prefetched_translations
attribute would be accessed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, I've overridden the formfield_for_foreignkey
method now to eliminate the similar queries
@@ -661,6 +739,14 @@ class PersonAdmin(admin.ModelAdmin): | |||
readonly_fields = ('uuid',) | |||
search_fields = ('uuid', 'salutation', 'family_name', 'given_name', 'slug',) | |||
|
|||
def get_queryset(self, request): | |||
queryset = super().get_queryset(request) | |||
queryset = queryset.select_related( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than assigning queryset multiple times, it would be better to chain things like return super.get_queryset.select_related(...)...
queryset = super().get_queryset(request) | ||
queryset = queryset.prefetch_related( | ||
Prefetch('translations', queryset=LevelTypeTranslation.objects.all(), to_attr='translated_names') | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[style] Same comment as above
7b245bc
to
4de5a65
Compare
4de5a65
to
e7986d6
Compare
PROD-4225
This PR adds the
get_queryset
method to Django Admin registered models. The aim is to optimize database queries and reduce query counts wherever possible by customizing the way queries are fetched in the admin interface. It will avoid unnecessary data fetching and reduce overhead.Screenshots
Before:
After:
Before:
After:
Before:
After:
and so on...