|
1 | 1 | use std::{ |
| 2 | + cell::Cell, |
2 | 3 | collections::VecDeque, |
3 | 4 | env, |
4 | 5 | fmt::{self, Write as _}, |
@@ -673,54 +674,59 @@ impl Remote { |
673 | 674 | async fn list_revisions( |
674 | 675 | &self, |
675 | 676 | channel: Branch, |
676 | | - releases: impl IntoIterator<Item = Release>, |
| 677 | + release: Release, |
677 | 678 | mut callback: impl FnMut(Sha, String), |
678 | 679 | ) -> 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 | + }; |
703 | 702 | } |
704 | 703 | Ok(()) |
705 | 704 | } |
706 | 705 |
|
707 | 706 | async fn channel_json( |
708 | 707 | &self, |
709 | 708 | channel: Branch, |
710 | | - releases: impl IntoIterator<Item = Release>, |
| 709 | + releases: impl Iterator<Item = Release>, |
711 | 710 | inc: impl Fn(), |
712 | 711 | ) -> 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 | + })) |
718 | 722 | .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. |
724 | 730 | let key = PrefixId::new(); |
725 | 731 | for prefix in pairs.values() { |
726 | 732 | if key.get(prefix).is_none() { |
|
0 commit comments