@@ -4,6 +4,7 @@ import { fetchRepos } from "./orchestrator_repos";
44import { getOrgSettings , updateOrgSettings } from "./orchestrator_orgs" ;
55import { testSlackWebhook } from "./drift_slack" ;
66import { fetchProjects , updateProject , fetchProject } from "./orchestrator_projects" ;
7+ import { timeAsync } from "@/lib/perf.server" ;
78
89export const getOrgSettingsFn = createServerFn ( { method : 'GET' } )
910 . inputValidator ( ( data : { userId : string , organisationId : string } ) => data )
@@ -28,7 +29,10 @@ export const getProjectsFn = createServerFn({method: 'GET'})
2829 } )
2930 . handler ( async ( { data } ) => {
3031 try {
31- const projects : any = await fetchProjects ( data . organisationId , data . userId )
32+ const projects : any = await timeAsync (
33+ `fetchProjects(org=${ data . organisationId } )` ,
34+ ( ) => fetchProjects ( data . organisationId , data . userId )
35+ )
3236 return projects . result || [ ]
3337 } catch ( error ) {
3438 console . error ( 'Error in getProjectsFn:' , error )
@@ -49,7 +53,10 @@ export const getReposFn = createServerFn({method: 'GET'})
4953 . handler ( async ( { data } ) => {
5054 let repos = [ ]
5155 try {
52- const reposData :any = await fetchRepos ( data . organisationId , data . userId )
56+ const reposData :any = await timeAsync (
57+ `fetchRepos(org=${ data . organisationId } )` ,
58+ ( ) => fetchRepos ( data . organisationId , data . userId )
59+ )
5360 repos = reposData . result
5461 } catch ( error ) {
5562 console . error ( 'Error fetching repos:' , error )
@@ -61,7 +68,10 @@ export const getReposFn = createServerFn({method: 'GET'})
6168export const getProjectFn = createServerFn ( { method : 'GET' } )
6269 . inputValidator ( ( data : { projectId : string , organisationId : string , userId : string } ) => data )
6370 . handler ( async ( { data } ) => {
64- const project : any = await fetchProject ( data . projectId , data . organisationId , data . userId )
71+ const project : any = await timeAsync (
72+ `fetchProject(${ data . projectId } )` ,
73+ ( ) => fetchProject ( data . projectId , data . organisationId , data . userId )
74+ )
6575 return project
6676 } )
6777
@@ -73,23 +83,29 @@ export const getRepoDetailsFn = createServerFn({method: 'GET'})
7383 let allJobs : Job [ ] = [ ] ;
7484 let repo : Repo
7585 try {
76- const response = await fetch ( `${ process . env . ORCHESTRATOR_BACKEND_URL } /api/repos/${ repoId } /jobs` , {
77- method : 'GET' ,
78- headers : {
79- 'Authorization' : `Bearer ${ process . env . ORCHESTRATOR_BACKEND_SECRET } ` ,
80- 'DIGGER_ORG_ID' : organisationId ,
81- 'DIGGER_USER_ID' : userId ,
82- 'DIGGER_ORG_SOURCE' : 'workos' ,
83- } ,
84- } ) ;
85-
86- if ( ! response . ok ) {
87- throw new Error ( 'Failed to fetch jobs' ) ;
88- }
89-
90- const data :any = await response . json ( ) ;
91- repo = data . repo
92- allJobs = data . jobs || [ ]
86+ const result = await timeAsync (
87+ `fetchRepoJobs(${ repoId } )` ,
88+ async ( ) => {
89+ const response = await fetch ( `${ process . env . ORCHESTRATOR_BACKEND_URL } /api/repos/${ repoId } /jobs` , {
90+ method : 'GET' ,
91+ headers : {
92+ 'Authorization' : `Bearer ${ process . env . ORCHESTRATOR_BACKEND_SECRET } ` ,
93+ 'DIGGER_ORG_ID' : organisationId ,
94+ 'DIGGER_USER_ID' : userId ,
95+ 'DIGGER_ORG_SOURCE' : 'workos' ,
96+ } ,
97+ } ) ;
98+
99+ if ( ! response . ok ) {
100+ throw new Error ( 'Failed to fetch jobs' ) ;
101+ }
102+
103+ return await response . json ( ) ;
104+ }
105+ ) ;
106+
107+ repo = result . repo
108+ allJobs = result . jobs || [ ]
93109
94110 } catch ( error ) {
95111 console . error ( 'Error fetching jobs:' , error ) ;
0 commit comments