Try to speed up

This commit is contained in:
Owen
2026-05-03 11:48:30 -07:00
parent c90e405105
commit bcd164219f

View File

@@ -38,10 +38,7 @@ import { calculateUserClientsForOrgs } from "@server/lib/calculateUserClientsFor
import { isSubscribed } from "#dynamic/lib/isSubscribed"; import { isSubscribed } from "#dynamic/lib/isSubscribed";
import { isLicensedOrSubscribed } from "#dynamic/lib/isLicencedOrSubscribed"; import { isLicensedOrSubscribed } from "#dynamic/lib/isLicencedOrSubscribed";
import { tierMatrix } from "@server/lib/billing/tierMatrix"; import { tierMatrix } from "@server/lib/billing/tierMatrix";
import { import { assignUserToOrg, removeUserFromOrg } from "@server/lib/userOrg";
assignUserToOrg,
removeUserFromOrg
} from "@server/lib/userOrg";
import { unwrapRoleMapping } from "@app/lib/idpRoleMapping"; import { unwrapRoleMapping } from "@app/lib/idpRoleMapping";
const ensureTrailingSlash = (url: string): string => { const ensureTrailingSlash = (url: string): string => {
@@ -336,23 +333,23 @@ export async function validateOidcCallback(
.innerJoin(orgs, eq(orgs.orgId, idpOrg.orgId)); .innerJoin(orgs, eq(orgs.orgId, idpOrg.orgId));
allOrgs = idpOrgs.map((o) => o.orgs); allOrgs = idpOrgs.map((o) => o.orgs);
for (const org of allOrgs) { // for (const org of allOrgs) {
const subscribed = await isSubscribed( // const subscribed = await isSubscribed(
org.orgId, // org.orgId,
tierMatrix.autoProvisioning // tierMatrix.autoProvisioning
); // );
if (!subscribed) { // if (!subscribed) {
// filter out the org // // filter out the org
allOrgs = allOrgs.filter((o) => o.orgId !== org.orgId); // allOrgs = allOrgs.filter((o) => o.orgId !== org.orgId);
// return next( // // return next(
// createHttpError( // // createHttpError(
// HttpCode.FORBIDDEN, // // HttpCode.FORBIDDEN,
// "This organization's current plan does not support this feature." // // "This organization's current plan does not support this feature."
// ) // // )
// ); // // );
} // }
} // }
} else { } else {
allOrgs = await db.select().from(orgs); allOrgs = await db.select().from(orgs);
} }
@@ -396,16 +393,14 @@ export async function validateOidcCallback(
idpOrgRes?.roleMapping || defaultRoleMapping; idpOrgRes?.roleMapping || defaultRoleMapping;
if (roleMapping) { if (roleMapping) {
logger.debug("Role Mapping", { roleMapping }); logger.debug("Role Mapping", { roleMapping });
const roleMappingJmes = unwrapRoleMapping( const roleMappingJmes =
roleMapping unwrapRoleMapping(roleMapping).evaluationExpression;
).evaluationExpression;
const roleMappingResult = jmespath.search( const roleMappingResult = jmespath.search(
claims, claims,
roleMappingJmes roleMappingJmes
); );
const roleNames = normalizeRoleMappingResult( const roleNames =
roleMappingResult normalizeRoleMappingResult(roleMappingResult);
);
const supportsMultiRole = await isLicensedOrSubscribed( const supportsMultiRole = await isLicensedOrSubscribed(
org.orgId, org.orgId,
@@ -515,7 +510,7 @@ export async function validateOidcCallback(
} }
} }
const orgUserCounts: { orgId: string; userCount: number }[] = []; const orgUserCounts: { orgId: string; userCount: number }[] = [];
// sync the user with the orgs and roles // sync the user with the orgs and roles
await db.transaction(async (trx) => { await db.transaction(async (trx) => {
@@ -628,7 +623,7 @@ export async function validateOidcCallback(
{ {
orgId: org.orgId, orgId: org.orgId,
userId: userId!, userId: userId!,
autoProvisioned: true, autoProvisioned: true
}, },
org.roleIds, org.roleIds,
trx trx
@@ -758,9 +753,7 @@ function hydrateOrgMapping(
return orgMapping.split("{{orgId}}").join(orgId); return orgMapping.split("{{orgId}}").join(orgId);
} }
function normalizeRoleMappingResult( function normalizeRoleMappingResult(result: unknown): string[] {
result: unknown
): string[] {
if (typeof result === "string") { if (typeof result === "string") {
const role = result.trim(); const role = result.trim();
return role ? [role] : []; return role ? [role] : [];
@@ -770,7 +763,9 @@ function normalizeRoleMappingResult(
return [ return [
...new Set( ...new Set(
result result
.filter((value): value is string => typeof value === "string") .filter(
(value): value is string => typeof value === "string"
)
.map((value) => value.trim()) .map((value) => value.trim())
.filter(Boolean) .filter(Boolean)
) )