Skip to content

Commit 5dcc538

Browse files
chore(web): Add debug logging to measure homepage load performance (#525)
1 parent 6710ac8 commit 5dcc538

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

packages/web/src/app/[domain]/page.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getRepos, getSearchContexts } from "@/actions";
22
import { Footer } from "@/app/components/footer";
33
import { getOrgFromDomain } from "@/data/org";
44
import { getConfiguredLanguageModelsInfo, getUserChatHistory } from "@/features/chat/actions";
5-
import { isServiceError } from "@/lib/utils";
5+
import { isServiceError, measure } from "@/lib/utils";
66
import { Homepage } from "./components/homepage";
77
import { NavigationMenu } from "./components/navigationMenu";
88
import { PageNotFound } from "./components/pageNotFound";
@@ -14,25 +14,36 @@ import { AGENTIC_SEARCH_TUTORIAL_DISMISSED_COOKIE_NAME, SEARCH_MODE_COOKIE_NAME
1414
import { env } from "@/env.mjs";
1515
import { loadJsonFile } from "@sourcebot/shared";
1616
import { DemoExamples, demoExamplesSchema } from "@/types";
17+
import { createLogger } from "@sourcebot/logger";
18+
19+
const logger = createLogger('web-homepage');
1720

1821
export default async function Home(props: { params: Promise<{ domain: string }> }) {
22+
logger.debug('Starting homepage load...');
23+
const { data: HomePage, durationMs } = await measure(() => HomeInternal(props), 'HomeInternal', /* outputLog = */ false);
24+
logger.debug(`Homepage load completed in ${durationMs}ms.`);
25+
26+
return HomePage;
27+
}
28+
29+
const HomeInternal = async (props: { params: Promise<{ domain: string }> }) => {
1930
const params = await props.params;
2031

2132
const {
2233
domain
2334
} = params;
2435

25-
const org = await getOrgFromDomain(domain);
36+
37+
const org = (await measure(() => getOrgFromDomain(domain), 'getOrgFromDomain')).data;
2638
if (!org) {
2739
return <PageNotFound />
2840
}
2941

30-
const session = await auth();
31-
32-
const models = await getConfiguredLanguageModelsInfo();
33-
const repos = await getRepos();
34-
const searchContexts = await getSearchContexts(domain);
35-
const chatHistory = session ? await getUserChatHistory(domain) : [];
42+
const session = (await measure(() => auth(), 'auth')).data;
43+
const models = (await measure(() => getConfiguredLanguageModelsInfo(), 'getConfiguredLanguageModelsInfo')).data;
44+
const repos = (await measure(() => getRepos(), 'getRepos')).data;
45+
const searchContexts = (await measure(() => getSearchContexts(domain), 'getSearchContexts')).data;
46+
const chatHistory = session ? (await measure(() => getUserChatHistory(domain), 'getUserChatHistory')).data : [];
3647

3748
if (isServiceError(repos)) {
3849
throw new ServiceErrorException(repos);
@@ -50,7 +61,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>
5061

5162
// Read search mode from cookie, defaulting to agentic if not set
5263
// (assuming a language model is configured).
53-
const cookieStore = await cookies();
64+
const cookieStore = (await measure(() => cookies(), 'cookies')).data;
5465
const searchModeCookie = cookieStore.get(SEARCH_MODE_COOKIE_NAME);
5566
const initialSearchMode = (
5667
searchModeCookie?.value === "agentic" ||
@@ -61,7 +72,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>
6172

6273
const demoExamples = env.SOURCEBOT_DEMO_EXAMPLES_PATH ? await (async () => {
6374
try {
64-
return await loadJsonFile<DemoExamples>(env.SOURCEBOT_DEMO_EXAMPLES_PATH!, demoExamplesSchema);
75+
return (await measure(() => loadJsonFile<DemoExamples>(env.SOURCEBOT_DEMO_EXAMPLES_PATH!, demoExamplesSchema), 'loadExamplesJsonFile')).data;
6576
} catch (error) {
6677
console.error('Failed to load demo examples:', error);
6778
return undefined;
@@ -87,4 +98,4 @@ export default async function Home(props: { params: Promise<{ domain: string }>
8798
<Footer />
8899
</div>
89100
)
90-
}
101+
}

0 commit comments

Comments
 (0)