Skip to content

Commit dfa6cea

Browse files
committed
Include bundle hash in revision
1 parent 1f928e9 commit dfa6cea

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

bundler/src/bundle.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use crate::permissionables::{proposals::Proposals, sessions::Sessions};
22
use flate2::{write::GzEncoder, Compression};
33
use serde::Serialize;
44
use sqlx::MySqlPool;
5+
use std::{
6+
collections::hash_map::DefaultHasher,
7+
hash::{Hash, Hasher},
8+
};
59
use tar::Header;
610

711
#[derive(Debug, Serialize)]
@@ -10,7 +14,7 @@ struct WasmModule {
1014
pub module: String,
1115
}
1216

13-
#[derive(Debug, Serialize)]
17+
#[derive(Debug, Hash, Serialize)]
1418
pub struct NoMetadata;
1519

1620
#[derive(Debug, Serialize)]
@@ -48,12 +52,18 @@ where
4852

4953
impl<Metadata> Bundle<Metadata>
5054
where
51-
Metadata: Serialize,
55+
Metadata: Hash + Serialize,
5256
{
5357
pub fn new(metadata: Metadata, proposals: Proposals, sessions: Sessions) -> Self {
58+
let mut hasher = DefaultHasher::new();
59+
metadata.hash(&mut hasher);
60+
proposals.hash(&mut hasher);
61+
sessions.hash(&mut hasher);
62+
let hash = hasher.finish();
63+
5464
Self {
5565
manifest: Manifest {
56-
revision: crate::built_info::PKG_VERSION.to_string(),
66+
revision: format!("{}:{}", crate::built_info::PKG_VERSION, hash),
5767
roots: vec!["diamond".to_string()],
5868
wasm: vec![],
5969
metadata,

bundler/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use clap::Parser;
88
use serde::Serialize;
99
use sqlx::{mysql::MySqlPoolOptions, MySqlPool};
1010
use std::{
11+
hash::Hash,
1112
marker::PhantomData,
1213
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
1314
ops::Add,
@@ -33,7 +34,7 @@ where
3334

3435
impl<Metadata> TryFrom<Bundle<Metadata>> for BundleFile<Metadata>
3536
where
36-
Metadata: Serialize,
37+
Metadata: Hash + Serialize,
3738
{
3839
type Error = anyhow::Error;
3940

bundler/src/permissionables/proposals.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use serde::Serialize;
22
use sqlx::{query_as, MySqlPool};
3-
use std::collections::HashMap;
3+
use std::collections::BTreeMap;
44

5-
#[derive(Debug, Default, PartialEq, Eq, Serialize)]
6-
pub struct Proposals(HashMap<String, Vec<u32>>);
5+
#[derive(Debug, Default, PartialEq, Eq, Hash, Serialize)]
6+
pub struct Proposals(BTreeMap<String, Vec<u32>>);
77

88
impl Proposals {
99
pub async fn fetch(ispyb_pool: &MySqlPool) -> Result<Self, sqlx::Error> {
@@ -55,12 +55,12 @@ impl FromIterator<ProposalRow> for Proposals {
5555
mod tests {
5656
use super::Proposals;
5757
use sqlx::MySqlPool;
58-
use std::collections::{HashMap, HashSet};
58+
use std::collections::{BTreeMap, BTreeSet};
5959

6060
#[sqlx::test(migrations = "tests/migrations")]
6161
async fn fetch_empty(ispyb_pool: MySqlPool) {
6262
let proposals = Proposals::fetch(&ispyb_pool).await.unwrap();
63-
let expected = Proposals(HashMap::new());
63+
let expected = Proposals(BTreeMap::new());
6464
assert_eq!(expected, proposals);
6565
}
6666

@@ -73,9 +73,9 @@ mod tests {
7373
)]
7474
async fn fetch_some(ispyb_pool: MySqlPool) {
7575
let proposals = Proposals::fetch(&ispyb_pool).await.unwrap();
76-
let mut expected = HashMap::new();
77-
expected.insert("foo".to_string(), HashSet::from([100, 101, 102]));
78-
expected.insert("bar".to_string(), HashSet::from([100]));
76+
let mut expected = BTreeMap::new();
77+
expected.insert("foo".to_string(), BTreeSet::from([100, 101, 102]));
78+
expected.insert("bar".to_string(), BTreeSet::from([100]));
7979
assert_eq!(
8080
expected,
8181
proposals

bundler/src/permissionables/sessions.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use serde::Serialize;
22
use sqlx::{query_as, MySqlPool};
3-
use std::collections::HashMap;
3+
use std::collections::BTreeMap;
44

5-
#[derive(Debug, Default, PartialEq, Eq, Serialize)]
6-
pub struct Sessions(HashMap<String, Vec<(u32, u32)>>);
5+
#[derive(Debug, Default, PartialEq, Eq, Hash, Serialize)]
6+
pub struct Sessions(BTreeMap<String, Vec<(u32, u32)>>);
77

88
impl Sessions {
99
pub async fn fetch(ispyb_pool: &MySqlPool) -> Result<Self, sqlx::Error> {
@@ -65,12 +65,12 @@ impl FromIterator<SessionRow> for Sessions {
6565
mod tests {
6666
use super::Sessions;
6767
use sqlx::MySqlPool;
68-
use std::collections::{HashMap, HashSet};
68+
use std::collections::{BTreeMap, BTreeSet};
6969

7070
#[sqlx::test(migrations = "tests/migrations")]
7171
async fn fetch_empty(ispyb_pool: MySqlPool) {
7272
let sessions = Sessions::fetch(&ispyb_pool).await.unwrap();
73-
let expected = Sessions(HashMap::new());
73+
let expected = Sessions(BTreeMap::new());
7474
assert_eq!(expected, sessions);
7575
}
7676

@@ -83,7 +83,7 @@ mod tests {
8383
)]
8484
async fn fetch_direct(ispyb_pool: MySqlPool) {
8585
let sessions = Sessions::fetch(&ispyb_pool).await.unwrap();
86-
let mut expected = HashMap::new();
86+
let mut expected = BTreeMap::new();
8787
expected.insert("foo".to_string(), vec![(100, 1), (100, 2)]);
8888
expected.insert("bar".to_string(), vec![(101, 1)]);
8989
assert_eq!(
@@ -105,14 +105,14 @@ mod tests {
105105
)]
106106
async fn fetch_indirect(ispyb_pool: MySqlPool) {
107107
let sessions = Sessions::fetch(&ispyb_pool).await.unwrap();
108-
let mut expected = HashMap::new();
108+
let mut expected = BTreeMap::new();
109109
expected.insert(
110110
"foo".to_string(),
111-
HashSet::from([(100, 1), (100, 2), (100, 3), (101, 1), (101, 2)]),
111+
BTreeSet::from([(100, 1), (100, 2), (100, 3), (101, 1), (101, 2)]),
112112
);
113113
expected.insert(
114114
"bar".to_string(),
115-
HashSet::from([(100, 1), (100, 2), (100, 3)]),
115+
BTreeSet::from([(100, 1), (100, 2), (100, 3)]),
116116
);
117117
assert_eq!(
118118
expected,
@@ -138,14 +138,14 @@ mod tests {
138138
)]
139139
async fn fetch_both(ispyb_pool: MySqlPool) {
140140
let sessions = Sessions::fetch(&ispyb_pool).await.unwrap();
141-
let mut expected = HashMap::new();
141+
let mut expected = BTreeMap::new();
142142
expected.insert(
143143
"foo".to_string(),
144-
HashSet::from([(100, 1), (100, 2), (100, 3), (101, 1), (101, 2)]),
144+
BTreeSet::from([(100, 1), (100, 2), (100, 3), (101, 1), (101, 2)]),
145145
);
146146
expected.insert(
147147
"bar".to_string(),
148-
HashSet::from([(100, 1), (100, 2), (100, 3), (101, 1)]),
148+
BTreeSet::from([(100, 1), (100, 2), (100, 3), (101, 1)]),
149149
);
150150
assert_eq!(
151151
expected,

0 commit comments

Comments
 (0)