fix slow tree loading times when hundreds of agents
This commit is contained in:
parent
fdf90be39b
commit
37327940bc
|
@ -18,7 +18,11 @@ class Client(models.Model):
|
||||||
@property
|
@property
|
||||||
def has_failing_checks(self):
|
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:
|
for agent in agents:
|
||||||
if agent.checks["has_failing_checks"]:
|
if agent.checks["has_failing_checks"]:
|
||||||
return True
|
return True
|
||||||
|
@ -43,7 +47,12 @@ class Site(models.Model):
|
||||||
@property
|
@property
|
||||||
def has_failing_checks(self):
|
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:
|
for agent in agents:
|
||||||
if agent.checks["has_failing_checks"]:
|
if agent.checks["has_failing_checks"]:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue