# Improves home_view()

* improves db fetching performance of landing page by ~75%
This commit is contained in:
mpeltriaux 2023-02-22 10:02:56 +01:00
parent 799b97341a
commit cea40cd878

View File

@ -35,6 +35,7 @@ def home_view(request: HttpRequest):
template = "konova/home.html"
now = timezone.now()
user = request.user
user_teams = user.shared_teams
# Fetch the four newest active and published ServerMessages
msgs = ServerMessage.objects.filter(
@ -51,7 +52,7 @@ def home_view(request: HttpRequest):
)
# Then fetch only user related ones
user_interventions = interventions.filter(
Q(users__in=[user]) | Q(teams__in=user.shared_teams)
Q(users__in=[user]) | Q(teams__in=user_teams)
).distinct()
# Repeat for other objects
@ -59,13 +60,13 @@ def home_view(request: HttpRequest):
deleted=None,
)
user_comps = comps.filter(
Q(intervention__users__in=[user]) | Q(intervention__teams__in=user.shared_teams)
Q(intervention__users__in=[user]) | Q(intervention__teams__in=user_teams)
).distinct()
eco_accs = EcoAccount.objects.filter(
deleted=None,
)
user_ecco_accs = eco_accs.filter(
Q(users__in=[user]) | Q(teams__in=user.shared_teams)
Q(users__in=[user]) | Q(teams__in=user_teams)
).distinct()
additional_context = {