Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: use Promise.all pattern for connected resources count, fix nested ternary

bernie-gd4640f71669d
diff --git a/backend/src/ee/services/gateway-pool/gateway-pool-dal.ts b/backend/src/ee/services/gateway-pool/gateway-pool-dal.ts
index 33c0e2f4b9..118b294293 100644
--- a/backend/src/ee/services/gateway-pool/gateway-pool-dal.ts
+++ b/backend/src/ee/services/gateway-pool/gateway-pool-dal.ts
@@ -35,9 +35,6 @@ export const gatewayPoolDalFactory = (db: TDbClient) => {
),
db.raw(
`COALESCE(array_agg(DISTINCT ${TableName.GatewayPoolMembership}."gatewayId") FILTER (WHERE ${TableName.GatewayPoolMembership}."gatewayId" IS NOT NULL), '{}') AS "memberGatewayIds"`
- ),
- db.raw(
- `(SELECT COUNT(*) FROM ${TableName.IdentityKubernetesAuth} WHERE ${TableName.IdentityKubernetesAuth}."gatewayPoolId" = ${TableName.GatewayPool}.id) AS "connectedResourcesCount"`
)
)
.groupBy(`${TableName.GatewayPool}.id`)
@@ -49,8 +46,7 @@ export const gatewayPoolDalFactory = (db: TDbClient) => {
...p,
memberCount: Number(raw.memberCount ?? 0),
healthyMemberCount: Number(raw.healthyMemberCount ?? 0),
- memberGatewayIds: (raw.memberGatewayIds as string[]) ?? [],
- connectedResourcesCount: Number(raw.connectedResourcesCount ?? 0)
+ memberGatewayIds: (raw.memberGatewayIds as string[]) ?? []
};
});
} catch (error) {
diff --git a/backend/src/ee/services/gateway-pool/gateway-pool-service.ts b/backend/src/ee/services/gateway-pool/gateway-pool-service.ts
index 386a136893..51b89064cb 100644
--- a/backend/src/ee/services/gateway-pool/gateway-pool-service.ts
+++ b/backend/src/ee/services/gateway-pool/gateway-pool-service.ts
@@ -95,7 +95,28 @@ export const gatewayPoolServiceFactory = ({
await $checkPermission(actor, OrgPermissionGatewayPoolActions.ListGatewayPools);
await $checkLicense(actor.orgId);
- return gatewayPoolDAL.findByOrgIdWithDetails(actor.orgId);
+ const pools = await gatewayPoolDAL.findByOrgIdWithDetails(actor.orgId);
+
+ if (pools.length === 0) return [];
+
+ // Add more DAL counts here as pool support expands to other consumers
+ const [k8sAuthCounts] = await Promise.all([
+ Promise.all(
+ pools.map((pool) =>
+ identityKubernetesAuthDAL.countByGatewayPoolId(pool.id).then((count) => ({ id: pool.id, count }))
+ )
+ )
+ ]);
+
+ const countMap = new Map<string, number>();
+ for (const { id, count } of k8sAuthCounts) {
+ countMap.set(id, (countMap.get(id) ?? 0) + count);
+ }
+
+ return pools.map((pool) => ({
+ ...pool,
+ connectedResourcesCount: countMap.get(pool.id) ?? 0
+ }));
};
const getGatewayPoolById = async ({ poolId, ...actor }: TGetGatewayPoolByIdDTO) => {
diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
index 6b658c7651..3d57e51624 100644
--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
@@ -1141,7 +1141,14 @@ export const identityKubernetesAuthServiceFactory = ({
gatewayV2IdValue = gatewayId;
}
}
- const gatewayPoolIdValue = gatewayPoolId !== undefined ? gatewayPoolId : (gatewayId !== undefined ? null : undefined);
+ let gatewayPoolIdValue: string | null | undefined;
+ if (gatewayPoolId !== undefined) {
+ gatewayPoolIdValue = gatewayPoolId;
+ } else if (gatewayId !== undefined) {
+ gatewayPoolIdValue = null;
+ } else {
+ gatewayPoolIdValue = undefined;
+ }
const effectiveTokenReviewMode = tokenReviewMode ?? identityKubernetesAuth.tokenReviewMode;
const effectiveKubernetesHost =