chore: performance tracking on root routes
This commit is contained in:
@@ -9,6 +9,7 @@ const APP_SUBDOMAINS = env.PRIVATE_APP_SUBDOMAINS?.split(',') || ['app'];
|
||||
const ORG_ID_COOKIE_PREFIX = 'cio_org_id_';
|
||||
|
||||
export const load = async ({ params, url, cookies }) => {
|
||||
const loadStart = performance.now();
|
||||
const subdomain = getSubdomain(url);
|
||||
const isOrgSite = subdomain && !APP_SUBDOMAINS.includes(subdomain);
|
||||
|
||||
@@ -22,14 +23,14 @@ export const load = async ({ params, url, cookies }) => {
|
||||
const cookieKey = `${ORG_ID_COOKIE_PREFIX}${siteName}`;
|
||||
const cachedOrgId = cookies.get(cookieKey);
|
||||
|
||||
console.log('cachedOrgId', cachedOrgId);
|
||||
console.log('cookieKey', cookieKey);
|
||||
|
||||
let orgId: string | undefined = cachedOrgId;
|
||||
let orgLookupMs = 0;
|
||||
|
||||
if (!orgId) {
|
||||
const orgLookupStart = performance.now();
|
||||
const apiKeyHeaders = getApiKeyHeaders();
|
||||
const org = await getOrgBySiteName(siteName, apiKeyHeaders);
|
||||
orgLookupMs = Math.round((performance.now() - orgLookupStart) * 100) / 100;
|
||||
|
||||
if (org?.id) {
|
||||
orgId = org.id;
|
||||
@@ -43,7 +44,10 @@ export const load = async ({ params, url, cookies }) => {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('returning orgId', orgId);
|
||||
const loadMs = Math.round((performance.now() - loadStart) * 100) / 100;
|
||||
console.log(
|
||||
`[org/+layout.server] load: ${loadMs}ms | siteName=${siteName} orgIdCache=${cachedOrgId ? 'hit' : 'miss'} getOrgBySiteName: ${orgLookupMs}ms`
|
||||
);
|
||||
|
||||
return {
|
||||
orgName: siteName,
|
||||
|
||||
@@ -5,13 +5,25 @@ type GetOrganizationSetupRequest = typeof classroomio.organization.setup.$get;
|
||||
type GetOrganizationSetupSuccess = Extract<InferResponseType<GetOrganizationSetupRequest>, { success: true }>;
|
||||
|
||||
export const load = async ({ params, parent, cookies }) => {
|
||||
const { orgId } = await parent();
|
||||
const loadStart = performance.now();
|
||||
const siteName = params.slug || '';
|
||||
|
||||
const parentStart = performance.now();
|
||||
const { orgId } = await parent();
|
||||
const parentMs = Math.round((performance.now() - parentStart) * 100) / 100;
|
||||
|
||||
const setupApiStart = performance.now();
|
||||
const result = await safeServerApi<GetOrganizationSetupSuccess>(() =>
|
||||
classroomio.organization.setup.$get({ query: { siteName } }, getApiHeaders(cookies, orgId))
|
||||
);
|
||||
const setupApiMs = Math.round((performance.now() - setupApiStart) * 100) / 100;
|
||||
|
||||
const setupProgress = result.ok ? result.body.data : null;
|
||||
const loadMs = Math.round((performance.now() - loadStart) * 100) / 100;
|
||||
|
||||
console.log(
|
||||
`[org/setup/+page.server] load: ${loadMs}ms | siteName=${siteName} parent: ${parentMs}ms organization.setup: ${setupApiMs}ms ok=${result.ok}`
|
||||
);
|
||||
|
||||
return {
|
||||
orgSiteName: siteName,
|
||||
|
||||
Reference in New Issue
Block a user