mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-08 15:14:52 +02:00
add caching
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
userResources,
|
userResources,
|
||||||
userSiteResources
|
userSiteResources
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
|
import { regionalCache as cache } from "#dynamic/lib/cache";
|
||||||
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 {
|
||||||
@@ -57,7 +58,18 @@ export type AccessibleIds = {
|
|||||||
siteResourceIds: number[];
|
siteResourceIds: number[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function resolveAccessibleIds(
|
const LAUNCHER_ACCESSIBLE_IDS_TTL_SEC = 60;
|
||||||
|
|
||||||
|
function launcherAccessibleIdsCacheKey(
|
||||||
|
orgId: string,
|
||||||
|
userId: string,
|
||||||
|
roleIds: number[]
|
||||||
|
) {
|
||||||
|
const rolesKey = [...roleIds].sort((a, b) => a - b).join(",");
|
||||||
|
return `launcherAccessibleIds:${orgId}:${userId}:${rolesKey}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolveAccessibleIdsUncached(
|
||||||
orgId: string,
|
orgId: string,
|
||||||
userId: string,
|
userId: string,
|
||||||
userRoleIds: number[]
|
userRoleIds: number[]
|
||||||
@@ -158,6 +170,26 @@ export async function resolveAccessibleIds(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function resolveAccessibleIds(
|
||||||
|
orgId: string,
|
||||||
|
userId: string,
|
||||||
|
userRoleIds: number[]
|
||||||
|
): Promise<AccessibleIds> {
|
||||||
|
const cacheKey = launcherAccessibleIdsCacheKey(orgId, userId, userRoleIds);
|
||||||
|
const cached = await cache.get<AccessibleIds>(cacheKey);
|
||||||
|
if (cached) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await resolveAccessibleIdsUncached(
|
||||||
|
orgId,
|
||||||
|
userId,
|
||||||
|
userRoleIds
|
||||||
|
);
|
||||||
|
await cache.set(cacheKey, result, LAUNCHER_ACCESSIBLE_IDS_TTL_SEC);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
function searchPattern(query: string) {
|
function searchPattern(query: string) {
|
||||||
return `%${query.trim()}%`;
|
return `%${query.trim()}%`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user