1+ use crate :: utils:: fetch;
12use handlebars:: {
23 Context , Handlebars , Helper , HelperResult , Output , RenderContext , RenderErrorReason ,
34} ;
@@ -48,17 +49,23 @@ pub fn encode_zulip_stream(
4849}
4950
5051#[ derive( Debug , Clone ) ]
51- pub struct RustTeams ( pub Vec < Team > ) ;
52+ pub struct RustTeams {
53+ pub teams : Vec < Team > ,
54+ pub archived_teams : Vec < Team > ,
55+ }
5256
5357impl RustTeams {
5458 #[ cfg( test) ]
5559 fn dummy ( teams : Vec < Team > ) -> Self {
56- RustTeams ( teams)
60+ RustTeams {
61+ teams,
62+ archived_teams : vec ! [ ] ,
63+ }
5764 }
5865
5966 pub fn index_data ( & self ) -> IndexData {
6067 let mut teams = self
61- . 0
68+ . teams
6269 . clone ( )
6370 . into_iter ( )
6471 . filter ( |team| team. website_data . is_some ( ) )
@@ -84,7 +91,7 @@ impl RustTeams {
8491 }
8592
8693 pub fn page_data ( & self , section : & str , team_page_name : & str ) -> anyhow:: Result < PageData > {
87- let teams = self . 0 . clone ( ) ;
94+ let teams = self . teams . clone ( ) ;
8895
8996 // Find the main team first
9097 let main_team = teams
@@ -187,6 +194,16 @@ impl RustTeams {
187194 other_teams,
188195 } )
189196 }
197+
198+ pub fn archived_teams ( & self ) -> ArchivedTeams {
199+ let mut teams: Vec < Team > = self . archived_teams . clone ( ) ;
200+ teams. sort_by_key ( |t| {
201+ let weight = t. website_data . as_ref ( ) . map ( |d| d. weight ) . unwrap_or ( 0 ) ;
202+ ( Reverse ( weight) , t. name . clone ( ) )
203+ } ) ;
204+
205+ ArchivedTeams { teams }
206+ }
190207}
191208
192209#[ derive( Serialize ) ]
@@ -214,21 +231,32 @@ pub struct PageData {
214231 other_teams : Vec < Team > ,
215232}
216233
234+ #[ derive( Serialize ) ]
235+ pub struct ArchivedTeams {
236+ teams : Vec < Team > ,
237+ }
238+
217239pub fn load_rust_teams ( ) -> anyhow:: Result < RustTeams > {
218240 println ! ( "Downloading Team API data" ) ;
219241
220- let mut response = ureq:: get ( format ! ( "{BASE_URL}/teams.json" ) ) . call ( ) ?;
221- if !response. status ( ) . is_success ( ) {
222- return Err ( anyhow:: anyhow!(
223- "Failed to download team API (HTTP status {}): {}" ,
224- response. status( ) ,
225- response. body_mut( ) . read_to_string( ) ?
226- ) ) ;
227- }
228-
229- let resp: Teams = response. body_mut ( ) . read_json ( ) ?;
230-
231- Ok ( RustTeams ( resp. teams . into_values ( ) . collect ( ) ) )
242+ // Parallelize the download to make website build faster
243+ let ( teams, archived_teams) = std:: thread:: scope ( |scope| {
244+ let teams = scope. spawn ( || -> anyhow:: Result < Teams > {
245+ let response = fetch ( & format ! ( "{BASE_URL}/teams.json" ) ) ?;
246+ Ok ( serde_json:: from_str ( & response) ?)
247+ } ) ;
248+ let archived_teams = scope. spawn ( || -> anyhow:: Result < Teams > {
249+ let response = fetch ( & format ! ( "{BASE_URL}/archived-teams.json" ) ) ?;
250+ Ok ( serde_json:: from_str ( & response) ?)
251+ } ) ;
252+ ( teams. join ( ) . unwrap ( ) , archived_teams. join ( ) . unwrap ( ) )
253+ } ) ;
254+ let ( teams, archived_teams) = ( teams?, archived_teams?) ;
255+
256+ Ok ( RustTeams {
257+ teams : teams. teams . into_values ( ) . collect ( ) ,
258+ archived_teams : archived_teams. teams . into_values ( ) . collect ( ) ,
259+ } )
232260}
233261
234262pub ( crate ) fn kind_to_str ( kind : TeamKind ) -> & ' static str {
0 commit comments