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

Investigate and fix N+1 query issue django#1806 #1857

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ def index(request):
if data is None:
metrics = []
for MC in Metric.__subclasses__():
metrics.extend(MC.objects.filter(show_on_dashboard=True))
metrics.extend(
MC.objects.filter(show_on_dashboard=True).prefetch_related("data")
)
metrics = sorted(metrics, key=operator.attrgetter("display_position"))

data = []
for metric in metrics:
data.append({"metric": metric, "latest": metric.data.latest()})
latest_data = metric.data.latest()
data.append({"metric": metric, "latest": latest_data})
cache.set(key, data, 60 * 60, version=generation)

return render(request, "dashboard/index.html", {"data": data})
Expand Down
16 changes: 1 addition & 15 deletions fundraising/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,11 @@ class DjangoHeroForm(forms.ModelForm):
logo = forms.FileField(
required=False,
help_text=_(
"If you've donated at least US $%d, you can submit your logo and "
"If you've donated at least US $%d in a calendar year, you can submit your logo and "
"we will display it, too."
)
% LEADERSHIP_LEVEL_AMOUNT,
)
is_visible = forms.BooleanField(
required=False,
label=_(
"Yes, display my name, URL, and logo on this site. "
"It'll be displayed shortly after we verify it."
),
)
is_subscribed = forms.BooleanField(
required=False,
label=_(
"Yes, the Django Software Foundation can inform me about "
"future fundraising campaigns by email."
),
)

class Meta:
model = DjangoHero
Expand Down