Skip to content

Commit

Permalink
fix: already borrowed
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker committed Dec 21, 2023
1 parent 52388a6 commit b8f7bb9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
23 changes: 11 additions & 12 deletions src/satellite/src/db/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,26 @@ fn assert_write_permission(
pub fn delete_docs(collection: &CollectionKey) -> Result<(), String> {
let rule = get_state_rule(collection)?;

match rule.mem() {
let keys = match rule.mem() {
Memory::Heap => STATE.with(|state| {
let binding = state.borrow();
let docs = get_docs_heap(collection, &binding.heap.db.db)?;
delete_docs_impl(&docs, collection, &rule)
get_docs_heap(collection, &state.borrow().heap.db.db)
.map(|docs| docs.into_iter().map(|(key, _)| key.clone()).collect())
}),
Memory::Stable => STATE.with(|state| {
let binding = state.borrow();
let stable = get_docs_stable(collection, &binding.stable.db)?;
let docs: Vec<(&Key, &Doc)> = stable.iter().map(|(key, doc)| (&key.key, doc)).collect();
delete_docs_impl(&docs, collection, &rule)
get_docs_stable(collection, &state.borrow().stable.db)
.map(|docs| docs.iter().map(|(key, _)| key.key.clone()).collect())
}),
}
}?;

delete_docs_impl(&keys, collection, &rule)
}

fn delete_docs_impl<'a>(
docs: &[(&'a Key, &'a Doc)],
fn delete_docs_impl(
keys: &Vec<Key>,
collection: &CollectionKey,
rule: &Rule,
) -> Result<(), String> {
for (key, _) in docs {
for key in keys {
delete_state_doc(collection, key, rule)?;
}

Expand Down
27 changes: 14 additions & 13 deletions src/satellite/src/storage/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,23 @@ pub fn delete_asset(
pub fn delete_assets(collection: &CollectionKey) -> Result<(), String> {
let rule = get_state_rule(collection)?;

match rule.mem() {
let full_paths = match rule.mem() {
Memory::Heap => STATE.with(|state| {
let binding = state.borrow();
let assets = get_assets_heap(collection, &binding.heap.storage.assets);
delete_assets_impl(&assets, collection, &rule)
get_assets_heap(collection, &state.borrow().heap.storage.assets)
.iter()
.map(|(_, asset)| asset.key.full_path.clone())
.collect()
}),
Memory::Stable => STATE.with(|state| {
let binding = state.borrow();
let stable = get_assets_stable(collection, &binding.stable.assets);
let assets: Vec<(&FullPath, &Asset)> = stable
let stable = get_assets_stable(collection, &state.borrow().stable.assets);
stable
.iter()
.map(|(_, asset)| (&asset.key.full_path, asset))
.collect();
delete_assets_impl(&assets, collection, &rule)
.map(|(_, asset)| asset.key.full_path.clone())
.collect()
}),
}
};

delete_assets_impl(&full_paths, collection, &rule)
}

pub fn list_assets(
Expand Down Expand Up @@ -287,11 +288,11 @@ fn delete_asset_impl(
}

fn delete_assets_impl(
assets: &Vec<(&FullPath, &Asset)>,
full_paths: &Vec<FullPath>,
collection: &CollectionKey,
rule: &Rule,
) -> Result<(), String> {
for (full_path, _) in assets {
for full_path in full_paths {
let deleted_asset = delete_state_asset(collection, full_path, rule);

match deleted_asset {
Expand Down

0 comments on commit b8f7bb9

Please sign in to comment.