@@ -13,56 +13,128 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
1313 const offset = pageToOffset ( page , limit ) ;
1414 const query = getQuery ( url ) ;
1515
16- const parsedQueries = queryParamToMap ( query || '[]' ) ;
17- queries . set ( parsedQueries ) ;
18- let activeDeployment : Models . Deployment | null = null ;
19- if ( data . function . deploymentId ) {
20- try {
21- activeDeployment = await sdk
22- . forProject ( params . region , params . project )
23- . functions . getDeployment ( {
24- functionId : params . function ,
25- deploymentId : data . function . deploymentId
26- } ) ;
27- } catch ( error ) {
28- // active deployment with the requested ID could not be found
29- activeDeployment = null ;
30- }
31- }
16+ const [ deploymentList , activeDeployment , repository ] = await Promise . all ( [
17+ loadDeploymentList ( {
18+ region : params . region ,
19+ project : params . project ,
20+ functionId : params . function ,
21+ limit,
22+ offset,
23+ query
24+ } ) ,
25+ data . function . deploymentId
26+ ? loadActiveDeployment ( {
27+ region : params . region ,
28+ project : params . project ,
29+ functionId : params . function ,
30+ deploymentId : data . function . deploymentId
31+ } )
32+ : Promise . resolve ( null ) ,
33+ data . function . installationId && data . function . providerRepositoryId
34+ ? loadRepository ( {
35+ region : params . region ,
36+ project : params . project ,
37+ installationId : data . function . installationId ,
38+ providerRepositoryId : data . function . providerRepositoryId
39+ } )
40+ : Promise . resolve ( null )
41+ ] ) ;
3242
3343 return {
3444 offset,
3545 limit,
3646 query,
3747 installations : data . installations ,
3848 activeDeployment,
39- deploymentList : await sdk
40- . forProject ( params . region , params . project )
41- . functions . listDeployments ( {
42- functionId : params . function ,
43- queries : [
44- Query . limit ( limit ) ,
45- Query . offset ( offset ) ,
46- Query . orderDesc ( '' ) ,
47- Query . select ( [
48- 'buildSize' ,
49- 'sourceSize' ,
50- 'totalSize' ,
51- 'buildDuration' ,
52- 'status' ,
53- 'type' ,
54- 'resourceId' ,
55- 'providerRepositoryUrl' ,
56- 'providerRepositoryOwner' ,
57- 'providerRepositoryName' ,
58- 'providerBranchUrl' ,
59- 'providerBranch' ,
60- 'providerCommitMessage' ,
61- 'providerCommitHash' ,
62- 'providerCommitUrl'
63- ] ) ,
64- ...parsedQueries . values ( )
65- ]
66- } )
49+ repository,
50+ deploymentList
6751 } ;
6852} ;
53+
54+ async function loadDeploymentList ( {
55+ region,
56+ project,
57+ functionId,
58+ limit,
59+ offset,
60+ query
61+ } : {
62+ region : string ;
63+ project : string ;
64+ functionId : string ;
65+ limit : number ;
66+ offset : number ;
67+ query : string ;
68+ } ) : Promise < Models . DeploymentList > {
69+ const parsedQueries = queryParamToMap ( query || '[]' ) ;
70+ queries . set ( parsedQueries ) ;
71+
72+ return sdk . forProject ( region , project ) . functions . listDeployments ( {
73+ functionId,
74+ queries : [
75+ Query . limit ( limit ) ,
76+ Query . offset ( offset ) ,
77+ Query . orderDesc ( '' ) ,
78+ Query . select ( [
79+ 'buildSize' ,
80+ 'sourceSize' ,
81+ 'totalSize' ,
82+ 'buildDuration' ,
83+ 'status' ,
84+ 'type' ,
85+ 'resourceId' ,
86+ 'providerRepositoryUrl' ,
87+ 'providerRepositoryOwner' ,
88+ 'providerRepositoryName' ,
89+ 'providerBranchUrl' ,
90+ 'providerBranch' ,
91+ 'providerCommitMessage' ,
92+ 'providerCommitHash' ,
93+ 'providerCommitUrl'
94+ ] ) ,
95+ ...parsedQueries . values ( )
96+ ]
97+ } ) ;
98+ }
99+
100+ async function loadActiveDeployment ( {
101+ region,
102+ project,
103+ functionId,
104+ deploymentId
105+ } : {
106+ region : string ;
107+ project : string ;
108+ functionId : string ;
109+ deploymentId : string ;
110+ } ) : Promise < Models . Deployment | null > {
111+ try {
112+ return await sdk . forProject ( region , project ) . functions . getDeployment ( {
113+ functionId,
114+ deploymentId
115+ } ) ;
116+ } catch ( error ) {
117+ return null ;
118+ }
119+ }
120+
121+ async function loadRepository ( {
122+ region,
123+ project,
124+ installationId,
125+ providerRepositoryId
126+ } : {
127+ region : string ;
128+ project : string ;
129+ installationId : string ;
130+ providerRepositoryId : string ;
131+ } ) : Promise < Models . ProviderRepository | null > {
132+ try {
133+ return await sdk . forProject ( region , project ) . vcs . getRepository ( {
134+ installationId,
135+ providerRepositoryId
136+ } ) ;
137+ } catch ( error ) {
138+ return null ;
139+ }
140+ }
0 commit comments