Skip to content

Commit a45a38b

Browse files
committed
Make fetch faster again
1 parent 1b55317 commit a45a38b

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

src/main.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
cell::Cell,
23
collections::VecDeque,
34
env,
45
fmt::{self, Write as _},
@@ -673,54 +674,59 @@ impl Remote {
673674
async fn list_revisions(
674675
&self,
675676
channel: Branch,
676-
releases: impl IntoIterator<Item = Release>,
677+
release: Release,
677678
mut callback: impl FnMut(Sha, String),
678679
) -> anyhow::Result<()> {
679-
for release in releases {
680-
let mut continuation_token = None;
681-
loop {
682-
let output = self
683-
.s3
684-
.list_objects_v2()
685-
.bucket(BUCKET)
686-
.prefix(channel.prefix(release))
687-
.delimiter("/")
688-
.set_continuation_token(continuation_token)
689-
.send()
690-
.await?;
691-
let prefixes = output
692-
.common_prefixes
693-
.unwrap_or_default()
694-
.into_iter()
695-
.map(|item| item.prefix.ok_or_else(|| anyhow!("missing prefix")))
696-
.collect::<anyhow::Result<VecDeque<String>>>()?;
697-
self.git_revisions(prefixes, &mut callback).await?;
698-
match output.next_continuation_token {
699-
Some(token) => continuation_token = Some(token),
700-
None => break,
701-
};
702-
}
680+
let mut continuation_token = None;
681+
loop {
682+
let output = self
683+
.s3
684+
.list_objects_v2()
685+
.bucket(BUCKET)
686+
.prefix(channel.prefix(release))
687+
.delimiter("/")
688+
.set_continuation_token(continuation_token)
689+
.send()
690+
.await?;
691+
let prefixes = output
692+
.common_prefixes
693+
.unwrap_or_default()
694+
.into_iter()
695+
.map(|item| item.prefix.ok_or_else(|| anyhow!("missing prefix")))
696+
.collect::<anyhow::Result<VecDeque<String>>>()?;
697+
self.git_revisions(prefixes, &mut callback).await?;
698+
match output.next_continuation_token {
699+
Some(token) => continuation_token = Some(token),
700+
None => break,
701+
};
703702
}
704703
Ok(())
705704
}
706705

707706
async fn channel_json(
708707
&self,
709708
channel: Branch,
710-
releases: impl IntoIterator<Item = Release>,
709+
releases: impl Iterator<Item = Release>,
711710
inc: impl Fn(),
712711
) -> anyhow::Result<String> {
713-
let mut pairs = IndexMap::new();
714-
self.list_revisions(channel, releases, |sha, prefix| {
715-
pairs.insert(sha, prefix);
716-
inc();
717-
})
712+
let cell = Cell::new(IndexMap::new());
713+
try_join_all(releases.map(|release| {
714+
self.list_revisions(channel, release, |sha, prefix| {
715+
let mut pairs = cell.take();
716+
pairs.insert(sha, prefix);
717+
let tmp = cell.replace(pairs);
718+
assert!(tmp.is_empty());
719+
inc();
720+
})
721+
}))
718722
.await?;
719-
// S3 lists things in lexicographical order, which doesn't necessarily match up with the
720-
// chronological order we want. First, the beta versions of stable channels get listed last,
721-
// even though they actually come first chronologically. Second, the integer ID that comes
722-
// before the commit hash prefix can have an arbitrary number of digits, which causes the
723-
// ordering to be wrong when e.g. an ID has few digits but a high leading digit.
723+
let mut pairs = cell.into_inner();
724+
// We handled the list of releases concurrently, but even if we didn't, S3 lists things in
725+
// lexicographical order, which doesn't necessarily match up with the chronological order we
726+
// want. First, the beta versions of stable channels get listed last, even though they
727+
// actually come first chronologically. Second, the integer ID that comes before the commit
728+
// hash prefix can have an arbitrary number of digits, which causes the ordering to be wrong
729+
// when e.g. an ID has few digits but a high leading digit.
724730
let key = PrefixId::new();
725731
for prefix in pairs.values() {
726732
if key.get(prefix).is_none() {

0 commit comments

Comments
 (0)