From 37327940bc6ddb994ad09af718bcaa56bb1f12b3 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 29 Jun 2020 02:57:21 +0000 Subject: [PATCH] fix slow tree loading times when hundreds of agents --- api/tacticalrmm/clients/models.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/api/tacticalrmm/clients/models.py b/api/tacticalrmm/clients/models.py index 37be469d..57e3468c 100644 --- a/api/tacticalrmm/clients/models.py +++ b/api/tacticalrmm/clients/models.py @@ -18,7 +18,11 @@ class Client(models.Model): @property def has_failing_checks(self): - agents = Agent.objects.filter(client=self.client) + agents = ( + Agent.objects.only("pk") + .filter(client=self.client) + .prefetch_related("agentchecks") + ) for agent in agents: if agent.checks["has_failing_checks"]: return True @@ -43,7 +47,12 @@ class Site(models.Model): @property def has_failing_checks(self): - agents = Agent.objects.filter(client=self.client.client).filter(site=self.site) + agents = ( + Agent.objects.only("pk") + .filter(client=self.client.client) + .filter(site=self.site) + .prefetch_related("agentchecks") + ) for agent in agents: if agent.checks["has_failing_checks"]: return True