Clear duplicate deck setting keys on downgrade

This commit is contained in:
RumovZ 2022-07-09 21:42:40 +02:00
parent 4ee7be1e10
commit 138a03b6b0
2 changed files with 10 additions and 2 deletions

View file

@ -362,11 +362,12 @@ impl From<Deck> for DeckSchema11 {
impl From<Deck> for DeckCommonSchema11 {
fn from(deck: Deck) -> Self {
let other: HashMap<String, Value> = if deck.common.other.is_empty() {
let mut other: HashMap<String, Value> = if deck.common.other.is_empty() {
Default::default()
} else {
serde_json::from_slice(&deck.common.other).unwrap_or_default()
};
clear_other_duplicates(&mut other);
DeckCommonSchema11 {
id: deck.id,
mtime: deck.mtime_secs,
@ -393,6 +394,13 @@ impl From<Deck> for DeckCommonSchema11 {
}
}
/// See [crate::deckconfig::schema11::clear_other_duplicates()].
fn clear_other_duplicates(other: &mut HashMap<String, Value>) {
for key in ["review_limit", "new_limit"] {
other.remove(key);
}
}
impl From<&Deck> for DeckTodaySchema11 {
fn from(deck: &Deck) -> Self {
let day = deck.common.last_day_studied as i32;

View file

@ -159,8 +159,8 @@ impl From<Notetype> for NotetypeSchema11 {
}
}
/// See [crate::deckconfig::schema11::clear_other_duplicates()].
fn clear_other_field_duplicates(other: &mut HashMap<String, Value>) {
// see `clear_other_duplicates()` in `deckconfig/schema11.rs`
for key in &["description"] {
other.remove(*key);
}