mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-05 19:17:29 -06:00
Address code review feedback: simplify logic and improve performance
Co-authored-by: oschwartz10612 <4999704+oschwartz10612@users.noreply.github.com>
This commit is contained in:
@@ -80,12 +80,12 @@ export async function updateClientResources(
|
||||
//
|
||||
// Recommended practice:
|
||||
// Use unique names per site: app-host1, app-host2
|
||||
if (existingResource && siteId && existingResource.siteId !== siteId) {
|
||||
if (existingResource && existingResource.siteId !== site.siteId) {
|
||||
// Get site information for better error messaging
|
||||
const [currentSite] = await trx
|
||||
.select({ niceId: sites.niceId, name: sites.name })
|
||||
.from(sites)
|
||||
.where(eq(sites.siteId, siteId))
|
||||
.where(eq(sites.siteId, site.siteId))
|
||||
.limit(1);
|
||||
|
||||
const [existingSite] = await trx
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
users
|
||||
} from "@server/db";
|
||||
import { resources, targets, sites } from "@server/db";
|
||||
import { eq, and, asc, or, ne, count, isNotNull } from "drizzle-orm";
|
||||
import { eq, and, asc, or, ne, count, isNotNull, inArray } from "drizzle-orm";
|
||||
import {
|
||||
Config,
|
||||
ConfigSchema,
|
||||
@@ -199,7 +199,7 @@ export async function updateProxyResources(
|
||||
(target) => target.siteId !== siteId
|
||||
);
|
||||
|
||||
if (hasTargetsFromDifferentSite && existingTargets.length > 0) {
|
||||
if (hasTargetsFromDifferentSite) {
|
||||
// Get site information for better error messaging
|
||||
const [currentSite] = await trx
|
||||
.select({ niceId: sites.niceId, name: sites.name })
|
||||
@@ -213,9 +213,7 @@ export async function updateProxyResources(
|
||||
const existingSites = await trx
|
||||
.select({ niceId: sites.niceId, name: sites.name })
|
||||
.from(sites)
|
||||
.where(
|
||||
or(...existingSiteIds.map((id) => eq(sites.siteId, id)))
|
||||
);
|
||||
.where(inArray(sites.siteId, existingSiteIds));
|
||||
|
||||
const existingSiteNames = existingSites
|
||||
.map((s) => s.name || s.niceId)
|
||||
|
||||
Reference in New Issue
Block a user