Enhance performance logging in course loading process by measuring load times for organization courses and tags API calls; include self-hosted environment variable in logs for better observability.
This commit is contained in:
@@ -1,10 +1,19 @@
|
|||||||
import { classroomio, getApiHeaders } from '$lib/utils/services/api';
|
import { classroomio, getApiHeaders } from '$lib/utils/services/api';
|
||||||
|
|
||||||
|
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
|
||||||
|
|
||||||
export const load = async ({ parent, locals, cookies, url }) => {
|
export const load = async ({ parent, locals, cookies, url }) => {
|
||||||
|
const loadStart = performance.now();
|
||||||
|
|
||||||
const tagsParam = url.searchParams.get('tags');
|
const tagsParam = url.searchParams.get('tags');
|
||||||
const { orgId } = await parent();
|
const { orgId } = await parent();
|
||||||
|
|
||||||
if (!orgId || !locals.user?.id) {
|
if (!orgId || !locals.user?.id) {
|
||||||
|
const loadMs = Math.round((performance.now() - loadStart) * 100) / 100;
|
||||||
|
console.log(
|
||||||
|
`[org/[slug]/courses +page.server] load: ${loadMs}ms (skipped: no orgId or user) | PUBLIC_IS_SELFHOSTED=${PUBLIC_IS_SELFHOSTED}`
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
courses: []
|
courses: []
|
||||||
};
|
};
|
||||||
@@ -16,6 +25,7 @@ export const load = async ({ parent, locals, cookies, url }) => {
|
|||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
const normalizedTagsQuery = normalizedTags && normalizedTags.length > 0 ? normalizedTags.join(',') : undefined;
|
const normalizedTagsQuery = normalizedTags && normalizedTags.length > 0 ? normalizedTags.join(',') : undefined;
|
||||||
|
|
||||||
|
const apiStart = performance.now();
|
||||||
const [coursesResponse, tagsResponse] = await Promise.all([
|
const [coursesResponse, tagsResponse] = await Promise.all([
|
||||||
classroomio.organization.courses.$get(
|
classroomio.organization.courses.$get(
|
||||||
normalizedTagsQuery
|
normalizedTagsQuery
|
||||||
@@ -24,16 +34,23 @@ export const load = async ({ parent, locals, cookies, url }) => {
|
|||||||
tags: normalizedTagsQuery
|
tags: normalizedTagsQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
: {},
|
: { query: {} },
|
||||||
getApiHeaders(cookies, orgId)
|
getApiHeaders(cookies, orgId)
|
||||||
),
|
),
|
||||||
classroomio.organization.tags.$get({}, getApiHeaders(cookies, orgId))
|
classroomio.organization.tags.$get({}, getApiHeaders(cookies, orgId))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [coursesData, tagsData] = await Promise.all([coursesResponse.json(), tagsResponse.json()]);
|
const [coursesData, tagsData] = await Promise.all([coursesResponse.json(), tagsResponse.json()]);
|
||||||
|
const apiMs = Math.round((performance.now() - apiStart) * 100) / 100;
|
||||||
|
|
||||||
const courses = coursesData.success ? coursesData.data : [];
|
const courses = coursesData.success ? coursesData.data : [];
|
||||||
const tagGroups = tagsData.success ? tagsData.data : [];
|
const tagGroups = tagsData.success ? tagsData.data : [];
|
||||||
|
|
||||||
|
const loadMs = Math.round((performance.now() - loadStart) * 100) / 100;
|
||||||
|
console.log(
|
||||||
|
`[org/[slug]/courses +page.server] load: ${loadMs}ms (organization courses + tags API: ${apiMs}ms) | PUBLIC_IS_SELFHOSTED=${PUBLIC_IS_SELFHOSTED}`
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
courses: courses || [],
|
courses: courses || [],
|
||||||
activeTags: normalizedTags ?? [],
|
activeTags: normalizedTags ?? [],
|
||||||
|
|||||||
Reference in New Issue
Block a user