From 4c789225b2e13b08fe57a963c0135148c656568b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Ros?= Date: Thu, 30 Mar 2023 11:44:15 -0700 Subject: [PATCH 1/2] Added agent's custom fields to table result This action is to enable search and summary in the dashboard view. --- api/tacticalrmm/agents/serializers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/tacticalrmm/agents/serializers.py b/api/tacticalrmm/agents/serializers.py index bcc6e9ae..bc0b0b28 100644 --- a/api/tacticalrmm/agents/serializers.py +++ b/api/tacticalrmm/agents/serializers.py @@ -95,6 +95,7 @@ class AgentTableSerializer(serializers.ModelSerializer): local_ips = serializers.ReadOnlyField() make_model = serializers.ReadOnlyField() physical_disks = serializers.ReadOnlyField() + custom_fields = AgentCustomFieldSerializer(many=True, read_only=True) def get_alert_template(self, obj): if not obj.alert_template: @@ -153,6 +154,7 @@ class AgentTableSerializer(serializers.ModelSerializer): "local_ips", "make_model", "physical_disks", + "custom_fields", ] depth = 2 From 56124d2b50392f38561aefe9183566fe3b1ddcf0 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Tue, 4 Apr 2023 05:13:17 +0000 Subject: [PATCH 2/2] add prefetch to view to avoid n+1 queries --- api/tacticalrmm/agents/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 865c095b..5ecbf055 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -134,6 +134,10 @@ class GetAgents(APIView): "checkresults", queryset=CheckResult.objects.select_related("assigned_check"), ), + Prefetch( + "custom_fields", + queryset=AgentCustomField.objects.select_related("field"), + ), ) .annotate( has_patches_pending=Exists(