Skip to content

Commit c53ba8e

Browse files
committed
Download archived teams from the team API
1 parent 5c04d70 commit c53ba8e

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/teams.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,23 @@ pub fn encode_zulip_stream(
4949
}
5050

5151
#[derive(Debug, Clone)]
52-
pub struct RustTeams(pub Vec<Team>);
52+
pub struct RustTeams {
53+
pub teams: Vec<Team>,
54+
pub archived_teams: Vec<Team>,
55+
}
5356

5457
impl RustTeams {
5558
#[cfg(test)]
5659
fn dummy(teams: Vec<Team>) -> Self {
57-
RustTeams(teams)
60+
RustTeams {
61+
teams,
62+
archived_teams: vec![],
63+
}
5864
}
5965

6066
pub fn index_data(&self) -> IndexData {
6167
let mut teams = self
62-
.0
68+
.teams
6369
.clone()
6470
.into_iter()
6571
.filter(|team| team.website_data.is_some())
@@ -85,7 +91,7 @@ impl RustTeams {
8591
}
8692

8793
pub fn page_data(&self, section: &str, team_page_name: &str) -> anyhow::Result<PageData> {
88-
let teams = self.0.clone();
94+
let teams = self.teams.clone();
8995

9096
// Find the main team first
9197
let main_team = teams
@@ -218,10 +224,24 @@ pub struct PageData {
218224
pub fn load_rust_teams() -> anyhow::Result<RustTeams> {
219225
println!("Downloading Team API data");
220226

221-
let response = fetch(&format!("{BASE_URL}/teams.json"))?;
222-
let response: Teams = serde_json::from_str(&response)?;
223-
224-
Ok(RustTeams(response.teams.into_values().collect()))
227+
// Parallelize the download to make website build faster
228+
let (teams, archived_teams) = std::thread::scope(|scope| {
229+
let teams = scope.spawn(|| -> anyhow::Result<Teams> {
230+
let response = fetch(&format!("{BASE_URL}/teams.json"))?;
231+
Ok(serde_json::from_str(&response)?)
232+
});
233+
let archived_teams = scope.spawn(|| -> anyhow::Result<Teams> {
234+
let response = fetch(&format!("{BASE_URL}/archived-teams.json"))?;
235+
Ok(serde_json::from_str(&response)?)
236+
});
237+
(teams.join().unwrap(), archived_teams.join().unwrap())
238+
});
239+
let (teams, archived_teams) = (teams?, archived_teams?);
240+
241+
Ok(RustTeams {
242+
teams: teams.teams.into_values().collect(),
243+
archived_teams: archived_teams.teams.into_values().collect(),
244+
})
225245
}
226246

227247
pub(crate) fn kind_to_str(kind: TeamKind) -> &'static str {

0 commit comments

Comments
 (0)