@@ -2,7 +2,7 @@ import { getRepos, getSearchContexts } from "@/actions";
2
2
import { Footer } from "@/app/components/footer" ;
3
3
import { getOrgFromDomain } from "@/data/org" ;
4
4
import { getConfiguredLanguageModelsInfo , getUserChatHistory } from "@/features/chat/actions" ;
5
- import { isServiceError } from "@/lib/utils" ;
5
+ import { isServiceError , measure } from "@/lib/utils" ;
6
6
import { Homepage } from "./components/homepage" ;
7
7
import { NavigationMenu } from "./components/navigationMenu" ;
8
8
import { PageNotFound } from "./components/pageNotFound" ;
@@ -14,25 +14,36 @@ import { AGENTIC_SEARCH_TUTORIAL_DISMISSED_COOKIE_NAME, SEARCH_MODE_COOKIE_NAME
14
14
import { env } from "@/env.mjs" ;
15
15
import { loadJsonFile } from "@sourcebot/shared" ;
16
16
import { DemoExamples , demoExamplesSchema } from "@/types" ;
17
+ import { createLogger } from "@sourcebot/logger" ;
18
+
19
+ const logger = createLogger ( 'web-homepage' ) ;
17
20
18
21
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 } > } ) => {
19
30
const params = await props . params ;
20
31
21
32
const {
22
33
domain
23
34
} = params ;
24
35
25
- const org = await getOrgFromDomain ( domain ) ;
36
+
37
+ const org = ( await measure ( ( ) => getOrgFromDomain ( domain ) , 'getOrgFromDomain' ) ) . data ;
26
38
if ( ! org ) {
27
39
return < PageNotFound />
28
40
}
29
41
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 : [ ] ;
36
47
37
48
if ( isServiceError ( repos ) ) {
38
49
throw new ServiceErrorException ( repos ) ;
@@ -50,7 +61,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>
50
61
51
62
// Read search mode from cookie, defaulting to agentic if not set
52
63
// (assuming a language model is configured).
53
- const cookieStore = await cookies ( ) ;
64
+ const cookieStore = ( await measure ( ( ) => cookies ( ) , 'cookies' ) ) . data ;
54
65
const searchModeCookie = cookieStore . get ( SEARCH_MODE_COOKIE_NAME ) ;
55
66
const initialSearchMode = (
56
67
searchModeCookie ?. value === "agentic" ||
@@ -61,7 +72,7 @@ export default async function Home(props: { params: Promise<{ domain: string }>
61
72
62
73
const demoExamples = env . SOURCEBOT_DEMO_EXAMPLES_PATH ? await ( async ( ) => {
63
74
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 ;
65
76
} catch ( error ) {
66
77
console . error ( 'Failed to load demo examples:' , error ) ;
67
78
return undefined ;
@@ -87,4 +98,4 @@ export default async function Home(props: { params: Promise<{ domain: string }>
87
98
< Footer />
88
99
</ div >
89
100
)
90
- }
101
+ }
0 commit comments