diff --git a/apps/event-worker/src/target-scan/index.ts b/apps/event-worker/src/target-scan/index.ts
index 5a2c59b3..2f67562f 100644
--- a/apps/event-worker/src/target-scan/index.ts
+++ b/apps/event-worker/src/target-scan/index.ts
@@ -71,7 +71,7 @@ export const createTargetScanWorker = () =>
logger.info(
`Upserting ${targets.length} targets for provider ${tp.target_provider.id}`,
);
- await upsertTargets(db, tp.target_provider.id, targets);
+ await upsertTargets(db, targets);
} catch (error: any) {
logger.error(
`Error upserting targets for provider ${tp.target_provider.id}: ${error.message}`,
diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/TargetIcon.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/TargetIcon.tsx
index bf47f14c..d05a3724 100644
--- a/apps/webservice/src/app/[workspaceSlug]/_components/TargetIcon.tsx
+++ b/apps/webservice/src/app/[workspaceSlug]/_components/TargetIcon.tsx
@@ -1,5 +1,10 @@
import { SiKubernetes, SiTerraform } from "@icons-pack/react-simple-icons";
-import { IconServer, IconTarget, IconUsersGroup } from "@tabler/icons-react";
+import {
+ IconServer,
+ IconTarget,
+ IconUserDollar,
+ IconUsersGroup,
+} from "@tabler/icons-react";
export const TargetIcon: React.FC<{ version: string; kind?: string }> = ({
version,
@@ -7,6 +12,8 @@ export const TargetIcon: React.FC<{ version: string; kind?: string }> = ({
}) => {
if (kind?.toLowerCase().includes("shared"))
return ;
+ if (kind?.toLowerCase().includes("customer"))
+ return ;
if (version.includes("kubernetes"))
return ;
if (version.includes("vm") || version.includes("compute"))
diff --git a/apps/webservice/src/app/api/v1/target-providers/[providerId]/set/route.ts b/apps/webservice/src/app/api/v1/target-providers/[providerId]/set/route.ts
index 04d1fa79..b024a8df 100644
--- a/apps/webservice/src/app/api/v1/target-providers/[providerId]/set/route.ts
+++ b/apps/webservice/src/app/api/v1/target-providers/[providerId]/set/route.ts
@@ -56,7 +56,7 @@ export const PATCH = async (
workspaceId: provider.workspaceId,
}));
- const targets = await upsertTargets(db, provider.id, targetsToInsert);
+ const targets = await upsertTargets(db, targetsToInsert);
return NextResponse.json({ targets });
};
diff --git a/apps/webservice/src/app/api/v1/workspaces/[workspaceId]/targets/route.ts b/apps/webservice/src/app/api/v1/workspaces/[workspaceId]/targets/route.ts
index 74130227..56fecf83 100644
--- a/apps/webservice/src/app/api/v1/workspaces/[workspaceId]/targets/route.ts
+++ b/apps/webservice/src/app/api/v1/workspaces/[workspaceId]/targets/route.ts
@@ -66,7 +66,6 @@ export const PATCH = async (
const targets = await upsertTargets(
db,
- null,
parsedTargets.map((t) => ({ ...t, workspaceId })),
);
diff --git a/packages/job-dispatch/src/target.ts b/packages/job-dispatch/src/target.ts
index 0aa53c70..660bcac9 100644
--- a/packages/job-dispatch/src/target.ts
+++ b/packages/job-dispatch/src/target.ts
@@ -8,7 +8,6 @@ import {
eq,
inArray,
isNotNull,
- isNull,
} from "@ctrlplane/db";
import { db } from "@ctrlplane/db/client";
import {
@@ -24,14 +23,19 @@ import { dispatchJobsForNewTargets } from "./new-target.js";
const log = logger.child({ label: "upsert-targets" });
-const getExistingTargets = (db: Tx, providerId: string | null) =>
+const getExistingTargets = (
+ db: Tx,
+ workspaceId: string,
+ identifiers: string[],
+) =>
db
.select()
.from(target)
.where(
- providerId === null
- ? isNull(target.providerId)
- : eq(target.providerId, providerId),
+ and(
+ eq(target.workspaceId, workspaceId),
+ inArray(target.identifier, identifiers),
+ ),
);
const dispatchNewTargets = async (db: Tx, newTargets: Target[]) => {
@@ -74,11 +78,23 @@ const dispatchNewTargets = async (db: Tx, newTargets: Target[]) => {
export const upsertTargets = async (
tx: Tx,
- providerId: string | null,
targetsToInsert: Array }>,
) => {
try {
- const targetsBeforeInsert = await getExistingTargets(tx, providerId);
+ const targetsBeforeInsertPromises = _.chain(targetsToInsert)
+ .groupBy((t) => t.workspaceId)
+ .map(async (t) =>
+ getExistingTargets(
+ tx,
+ t[0]!.workspaceId,
+ t.map((t) => t.identifier),
+ ),
+ )
+ .value();
+
+ const targetsBeforeInsert = (
+ await Promise.all(targetsBeforeInsertPromises)
+ ).flat();
const targets = await tx
.insert(target)