Make backend deck deletion take vec of ids

This commit is contained in:
RumovZ 2021-02-26 19:52:02 +01:00
parent 2c25645975
commit f7c20e40b5
5 changed files with 25 additions and 14 deletions

View file

@ -68,6 +68,10 @@ message DeckID {
int64 did = 1; int64 did = 1;
} }
message DeckIDs {
repeated int64 dids = 1;
}
message DeckConfigID { message DeckConfigID {
int64 dcid = 1; int64 dcid = 1;
} }
@ -146,7 +150,7 @@ service BackendService {
rpc GetDeckLegacy(DeckID) returns (Json); rpc GetDeckLegacy(DeckID) returns (Json);
rpc GetDeckNames(GetDeckNamesIn) returns (DeckNames); rpc GetDeckNames(GetDeckNamesIn) returns (DeckNames);
rpc NewDeckLegacy(Bool) returns (Json); rpc NewDeckLegacy(Bool) returns (Json);
rpc RemoveDeck(DeckID) returns (Empty); rpc RemoveDecks(DeckIDs) returns (Empty);
rpc DragDropDecks(DragDropDecksIn) returns (Empty); rpc DragDropDecks(DragDropDecksIn) returns (Empty);
// deck config // deck config

View file

@ -69,6 +69,12 @@ impl From<pb::DeckId> for DeckID {
} }
} }
impl From<pb::DeckIDs> for Vec<DeckID> {
fn from(dids: pb::DeckIDs) -> Self {
dids.dids.into_iter().map(DeckID).collect()
}
}
impl From<pb::DeckConfigId> for DeckConfID { impl From<pb::DeckConfigId> for DeckConfID {
fn from(dcid: pb::DeckConfigId) -> Self { fn from(dcid: pb::DeckConfigId) -> Self {
DeckConfID(dcid.dcid) DeckConfID(dcid.dcid)

View file

@ -898,8 +898,8 @@ impl BackendService for Backend {
.map(Into::into) .map(Into::into)
} }
fn remove_deck(&self, input: pb::DeckId) -> BackendResult<Empty> { fn remove_decks(&self, input: pb::DeckIDs) -> BackendResult<Empty> {
self.with_col(|col| col.remove_deck_and_child_decks(input.into())) self.with_col(|col| col.remove_decks_and_child_decks(input.into()))
.map(Into::into) .map(Into::into)
} }

View file

@ -442,13 +442,13 @@ impl Collection {
self.storage.get_deck_id(&machine_name) self.storage.get_deck_id(&machine_name)
} }
pub fn remove_deck_and_child_decks(&mut self, did: DeckID) -> Result<()> { pub fn remove_decks_and_child_decks(&mut self, dids: Vec<DeckID>) -> Result<()> {
// fixme: vet cache clearing // fixme: vet cache clearing
self.state.deck_cache.clear(); self.state.deck_cache.clear();
self.transact(None, |col| { self.transact(None, |col| {
let usn = col.usn()?; let usn = col.usn()?;
for did in dids {
if let Some(deck) = col.storage.get_deck(did)? { if let Some(deck) = col.storage.get_deck(did)? {
let child_decks = col.storage.child_decks(&deck)?; let child_decks = col.storage.child_decks(&deck)?;
@ -460,6 +460,7 @@ impl Collection {
col.remove_single_deck(&deck, usn)?; col.remove_single_deck(&deck, usn)?;
} }
} }
}
Ok(()) Ok(())
}) })
} }
@ -775,7 +776,7 @@ mod test {
// delete top level // delete top level
let top = col.get_or_create_normal_deck("one")?; let top = col.get_or_create_normal_deck("one")?;
col.remove_deck_and_child_decks(top.id)?; col.remove_decks_and_child_decks(vec![top.id])?;
// should have come back as "Default+" due to conflict // should have come back as "Default+" due to conflict
assert_eq!(sorted_names(&col), vec!["default", "Default+"]); assert_eq!(sorted_names(&col), vec!["default", "Default+"]);

View file

@ -1522,7 +1522,7 @@ mod test {
col1.remove_cards_and_orphaned_notes(&[cardid])?; col1.remove_cards_and_orphaned_notes(&[cardid])?;
let usn = col1.usn()?; let usn = col1.usn()?;
col1.remove_note_only(noteid, usn)?; col1.remove_note_only(noteid, usn)?;
col1.remove_deck_and_child_decks(deckid)?; col1.remove_decks_and_child_decks(vec![deckid])?;
let out = ctx.normal_sync(&mut col1).await; let out = ctx.normal_sync(&mut col1).await;
assert_eq!(out.required, SyncActionRequired::NoChanges); assert_eq!(out.required, SyncActionRequired::NoChanges);