Skip to content

Commit 8b042be

Browse files
committed
perf(webapp): skip the admin read on the watch authorization path
1 parent 1dd8536 commit 8b042be

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

apps/webapp/app/services/dashboardAgentWatches.server.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,22 @@ export async function authorizeWatchEnvironment(params: {
8888

8989
if (!environment) return { ok: false, reason: "access_revoked" };
9090

91-
// Primary for the same reason as the membership read above.
92-
const user = await prisma.user.findFirst({
93-
where: { id: params.userId },
94-
select: { admin: true },
95-
});
96-
if (!user) return { ok: false, reason: "access_revoked" };
91+
// The gate only reads `isAdmin` while the admin preview is on, so this read is skipped
92+
// otherwise: it runs on every watch check, batch authorization and sweep finalisation.
93+
let isAdmin = false;
94+
if (env.DASHBOARD_AGENT_ADMIN_PREVIEW === "1") {
95+
// Primary for the same reason as the membership read above.
96+
const user = await prisma.user.findFirst({
97+
where: { id: params.userId },
98+
select: { admin: true },
99+
});
100+
if (!user) return { ok: false, reason: "access_revoked" };
101+
isAdmin = user.admin;
102+
}
97103

98104
const allowed = await canAccessDashboardAgent({
99105
userId: params.userId,
100-
isAdmin: user.admin,
106+
isAdmin,
101107
// A background check is never an impersonated session.
102108
isImpersonating: false,
103109
organizationSlug: environment.organization.slug,

0 commit comments

Comments
 (0)