# Improves home_view()
* improves db fetching performance of landing page by ~75%
This commit is contained in:
parent
acee9daab8
commit
073c39a970
@ -35,6 +35,7 @@ def home_view(request: HttpRequest):
|
|||||||
template = "konova/home.html"
|
template = "konova/home.html"
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
user = request.user
|
user = request.user
|
||||||
|
user_teams = user.shared_teams
|
||||||
|
|
||||||
# Fetch the four newest active and published ServerMessages
|
# Fetch the four newest active and published ServerMessages
|
||||||
msgs = ServerMessage.objects.filter(
|
msgs = ServerMessage.objects.filter(
|
||||||
@ -51,7 +52,7 @@ def home_view(request: HttpRequest):
|
|||||||
)
|
)
|
||||||
# Then fetch only user related ones
|
# Then fetch only user related ones
|
||||||
user_interventions = interventions.filter(
|
user_interventions = interventions.filter(
|
||||||
Q(users__in=[user]) | Q(teams__in=user.shared_teams)
|
Q(users__in=[user]) | Q(teams__in=user_teams)
|
||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
# Repeat for other objects
|
# Repeat for other objects
|
||||||
@ -59,13 +60,13 @@ def home_view(request: HttpRequest):
|
|||||||
deleted=None,
|
deleted=None,
|
||||||
)
|
)
|
||||||
user_comps = comps.filter(
|
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()
|
).distinct()
|
||||||
eco_accs = EcoAccount.objects.filter(
|
eco_accs = EcoAccount.objects.filter(
|
||||||
deleted=None,
|
deleted=None,
|
||||||
)
|
)
|
||||||
user_ecco_accs = eco_accs.filter(
|
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()
|
).distinct()
|
||||||
|
|
||||||
additional_context = {
|
additional_context = {
|
||||||
|
Loading…
Reference in New Issue
Block a user