Skip to content

Commit

Permalink
Reformat ddb entries
Browse files Browse the repository at this point in the history
  • Loading branch information
vlinkz committed Mar 4, 2024
1 parent ce4458a commit bc5ce1a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/ddb/batch_put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub async fn batch_store_put(
) -> Result<()> {
let ops = store
.iter()
.map(|(_, v)| {
.map(|(k, v)| {
WriteRequest::builder()
.set_put_request(Some({
let mut putreq = PutRequest::builder()
.item("store", AttributeValue::S(v.store.clone()))
.item("attribute", AttributeValue::S(v.attribute.clone()));
.item("store", AttributeValue::S(k.to_string()))
.item("attribute", AttributeValue::L(v.attribute.iter().map(|x| AttributeValue::S(x.to_string())).collect::<Vec<AttributeValue>>()));
if let Some(version) = &v.version {
putreq = putreq.item("version", AttributeValue::S(version.clone()));
}
Expand Down
3 changes: 1 addition & 2 deletions src/ddb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ pub mod batch_put;

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
pub struct Store {
pub attribute: String,
pub store: String,
pub attribute: Vec<String>,
pub version: Option<String>,
}

Expand Down
28 changes: 14 additions & 14 deletions src/ddb/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ pub async fn get_store(rev: &str) -> HashMap<String, Store> {

info!("nix-instantiate: got {} packages", output.len());

let store = output
.iter()
.filter_map(|(attr, pkg)| {
if let Some(outpath) = pkg.outputs.get("out") {
let store = Store {
attribute: attr.to_string(),
store: outpath.split("/").last().unwrap().to_string(),
version: pkg.version.clone(),
};

Some((attr.to_string(), store))
let mut store: HashMap<String, Store> = HashMap::new();
for (attr, pkg) in &output {
if let Some(outpath) = pkg.outputs.get("out") {
if let Some(store_val) = store.get_mut(outpath) {
store_val.attribute.push(attr.to_string());
} else {
None
store.insert(
outpath.to_string(),
Store {
attribute: vec![attr.to_string()],
version: pkg.version.clone(),
},
);
}
})
.collect::<HashMap<String, Store>>();
}
}

info!("nix-instantiate: got {} store paths", store.len());

Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn main() -> Result<()> {

let new_storeset = storeset
.iter()
.filter(|(_, v)| !paths.contains(&v.store.as_str()))
.filter(|(k, _v)| !paths.contains(&k.as_str()))
.map(|(k, v)| (k.to_string(), v.clone()))
.collect::<std::collections::HashMap<String, _>>();

Expand All @@ -125,9 +125,9 @@ async fn main() -> Result<()> {

file.write_all(
storeset
.values()
.map(|x| x.store.to_string())
.collect::<Vec<String>>()
.keys()
.map(String::to_string)
.collect::<Vec<_>>()
.join("\n")
.as_bytes(),
)
Expand Down

0 comments on commit bc5ce1a

Please sign in to comment.