From 8913e7548424b2624e3a07ae3db5e168e4cc83fb Mon Sep 17 00:00:00 2001
From: Matt Hook <hookenz@gmail.com>
Date: Tue, 9 Apr 2024 15:50:48 +1200
Subject: [PATCH] fix(services): speed up service count on the kubernetes
 dashboard [EE-6967] (#11526)

---
 app/react/kubernetes/dashboard/DashboardView.tsx          | 3 ++-
 .../ServicesView/ServicesDatatable/ServicesDatatable.tsx  | 1 +
 app/react/kubernetes/services/service.ts                  | 8 ++++----
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/app/react/kubernetes/dashboard/DashboardView.tsx b/app/react/kubernetes/dashboard/DashboardView.tsx
index 89c2a4d14..5f459af2d 100644
--- a/app/react/kubernetes/dashboard/DashboardView.tsx
+++ b/app/react/kubernetes/dashboard/DashboardView.tsx
@@ -34,7 +34,8 @@ export function DashboardView() {
   );
   const { data: services, ...servicesQuery } = useServicesForCluster(
     environmentId,
-    namespaceNames
+    namespaceNames,
+    { lookupApplications: false }
   );
   const { data: ingresses, ...ingressesQuery } = useIngresses(
     environmentId,
diff --git a/app/react/kubernetes/services/ServicesView/ServicesDatatable/ServicesDatatable.tsx b/app/react/kubernetes/services/ServicesView/ServicesDatatable/ServicesDatatable.tsx
index 23d04db35..9ef0fdecd 100644
--- a/app/react/kubernetes/services/ServicesView/ServicesDatatable/ServicesDatatable.tsx
+++ b/app/react/kubernetes/services/ServicesView/ServicesDatatable/ServicesDatatable.tsx
@@ -41,6 +41,7 @@ export function ServicesDatatable() {
     namespaceNames,
     {
       autoRefreshRate: tableState.autoRefreshRate * 1000,
+      lookupApplications: true,
     }
   );
 
diff --git a/app/react/kubernetes/services/service.ts b/app/react/kubernetes/services/service.ts
index 0239780df..52bdec91d 100644
--- a/app/react/kubernetes/services/service.ts
+++ b/app/react/kubernetes/services/service.ts
@@ -22,7 +22,7 @@ export const queryKeys = {
 export function useServicesForCluster(
   environmentId: EnvironmentId,
   namespaceNames?: string[],
-  options?: { autoRefreshRate?: number }
+  options?: { autoRefreshRate?: number; lookupApplications?: boolean }
 ) {
   return useQuery(
     queryKeys.clusterServices(environmentId),
@@ -32,7 +32,7 @@ export function useServicesForCluster(
       }
       const settledServicesPromise = await Promise.allSettled(
         namespaceNames.map((namespace) =>
-          getServices(environmentId, namespace, true)
+          getServices(environmentId, namespace, options?.lookupApplications)
         )
       );
       return compact(
@@ -87,14 +87,14 @@ export function useMutationDeleteServices(environmentId: EnvironmentId) {
 export async function getServices(
   environmentId: EnvironmentId,
   namespace: string,
-  lookupApps: boolean
+  lookupApplications?: boolean
 ) {
   try {
     const { data: services } = await axios.get<Array<Service>>(
       `kubernetes/${environmentId}/namespaces/${namespace}/services`,
       {
         params: {
-          lookupapplications: lookupApps,
+          lookupapplications: lookupApplications,
         },
       }
     );