Skip to content
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

Way to optimize ORM queries to the database with get_queryset() #358

Open
zobweyt opened this issue Feb 20, 2023 · 0 comments
Open

Way to optimize ORM queries to the database with get_queryset() #358

zobweyt opened this issue Feb 20, 2023 · 0 comments

Comments

@zobweyt
Copy link

zobweyt commented Feb 20, 2023

Using Django Debug Toolbar I noticed that the NotificationViewList that displays the list of all notifications loads Django ORM very much and creates a lot of queries to the database.

image

How can this be optimized? I think it's possible using get_queryset(), but I don't know exactly which object will be displayed in this list and there is no clean way to extend the view, so I can't make select_related() for all situations. Most likely it needs to be executed for GenericForeignKey.

Here is my template override file

<!-- BASE_DIR/templates/notifications/list.html -->
{% extends 'base.html' %}

{% block content %}
<ul class="notifications">
  {% for notice in notifications %}
    {% include 'notifications/notice.html' %}
  {% endfor %}
</ul>
{% endblock content %}

How can I reduce the load on the database and reduce queries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants