mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
chore(web): Add debug logging to measure homepage load performance (#525)
This commit is contained in:
parent
6710ac8e32
commit
5dcc538878
1 changed files with 22 additions and 11 deletions
|
|
@ -2,7 +2,7 @@ import { getRepos, getSearchContexts } from "@/actions";
|
||||||
import { Footer } from "@/app/components/footer";
|
import { Footer } from "@/app/components/footer";
|
||||||
import { getOrgFromDomain } from "@/data/org";
|
import { getOrgFromDomain } from "@/data/org";
|
||||||
import { getConfiguredLanguageModelsInfo, getUserChatHistory } from "@/features/chat/actions";
|
import { getConfiguredLanguageModelsInfo, getUserChatHistory } from "@/features/chat/actions";
|
||||||
import { isServiceError } from "@/lib/utils";
|
import { isServiceError, measure } from "@/lib/utils";
|
||||||
import { Homepage } from "./components/homepage";
|
import { Homepage } from "./components/homepage";
|
||||||
import { NavigationMenu } from "./components/navigationMenu";
|
import { NavigationMenu } from "./components/navigationMenu";
|
||||||
import { PageNotFound } from "./components/pageNotFound";
|
import { PageNotFound } from "./components/pageNotFound";
|
||||||
|
|
@ -14,25 +14,36 @@ import { AGENTIC_SEARCH_TUTORIAL_DISMISSED_COOKIE_NAME, SEARCH_MODE_COOKIE_NAME
|
||||||
import { env } from "@/env.mjs";
|
import { env } from "@/env.mjs";
|
||||||
import { loadJsonFile } from "@sourcebot/shared";
|
import { loadJsonFile } from "@sourcebot/shared";
|
||||||
import { DemoExamples, demoExamplesSchema } from "@/types";
|
import { DemoExamples, demoExamplesSchema } from "@/types";
|
||||||
|
import { createLogger } from "@sourcebot/logger";
|
||||||
|
|
||||||
|
const logger = createLogger('web-homepage');
|
||||||
|
|
||||||
export default async function Home(props: { params: Promise<{ domain: string }> }) {
|
export default async function Home(props: { params: Promise<{ domain: string }> }) {
|
||||||
|
logger.debug('Starting homepage load...');
|
||||||
|
const { data: HomePage, durationMs } = await measure(() => HomeInternal(props), 'HomeInternal', /* outputLog = */ false);
|
||||||
|
logger.debug(`Homepage load completed in ${durationMs}ms.`);
|
||||||
|
|
||||||
|
return HomePage;
|
||||||
|
}
|
||||||
|
|
||||||
|
const HomeInternal = async (props: { params: Promise<{ domain: string }> }) => {
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
domain
|
domain
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
const org = await getOrgFromDomain(domain);
|
|
||||||
|
const org = (await measure(() => getOrgFromDomain(domain), 'getOrgFromDomain')).data;
|
||||||
if (!org) {
|
if (!org) {
|
||||||
return <PageNotFound />
|
return <PageNotFound />
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await auth();
|
const session = (await measure(() => auth(), 'auth')).data;
|
||||||
|
const models = (await measure(() => getConfiguredLanguageModelsInfo(), 'getConfiguredLanguageModelsInfo')).data;
|
||||||
const models = await getConfiguredLanguageModelsInfo();
|
const repos = (await measure(() => getRepos(), 'getRepos')).data;
|
||||||
const repos = await getRepos();
|
const searchContexts = (await measure(() => getSearchContexts(domain), 'getSearchContexts')).data;
|
||||||
const searchContexts = await getSearchContexts(domain);
|
const chatHistory = session ? (await measure(() => getUserChatHistory(domain), 'getUserChatHistory')).data : [];
|
||||||
const chatHistory = session ? await getUserChatHistory(domain) : [];
|
|
||||||
|
|
||||||
if (isServiceError(repos)) {
|
if (isServiceError(repos)) {
|
||||||
throw new ServiceErrorException(repos);
|
throw new ServiceErrorException(repos);
|
||||||
|
|
@ -50,7 +61,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>
|
||||||
|
|
||||||
// Read search mode from cookie, defaulting to agentic if not set
|
// Read search mode from cookie, defaulting to agentic if not set
|
||||||
// (assuming a language model is configured).
|
// (assuming a language model is configured).
|
||||||
const cookieStore = await cookies();
|
const cookieStore = (await measure(() => cookies(), 'cookies')).data;
|
||||||
const searchModeCookie = cookieStore.get(SEARCH_MODE_COOKIE_NAME);
|
const searchModeCookie = cookieStore.get(SEARCH_MODE_COOKIE_NAME);
|
||||||
const initialSearchMode = (
|
const initialSearchMode = (
|
||||||
searchModeCookie?.value === "agentic" ||
|
searchModeCookie?.value === "agentic" ||
|
||||||
|
|
@ -61,7 +72,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>
|
||||||
|
|
||||||
const demoExamples = env.SOURCEBOT_DEMO_EXAMPLES_PATH ? await (async () => {
|
const demoExamples = env.SOURCEBOT_DEMO_EXAMPLES_PATH ? await (async () => {
|
||||||
try {
|
try {
|
||||||
return await loadJsonFile<DemoExamples>(env.SOURCEBOT_DEMO_EXAMPLES_PATH!, demoExamplesSchema);
|
return (await measure(() => loadJsonFile<DemoExamples>(env.SOURCEBOT_DEMO_EXAMPLES_PATH!, demoExamplesSchema), 'loadExamplesJsonFile')).data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load demo examples:', error);
|
console.error('Failed to load demo examples:', error);
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue