From 138a03b6b0bc93213931f4f735504c1cedade178 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sat, 9 Jul 2022 21:42:40 +0200 Subject: [PATCH] Clear duplicate deck setting keys on downgrade --- rslib/src/decks/schema11.rs | 10 +++++++++- rslib/src/notetype/schema11.rs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rslib/src/decks/schema11.rs b/rslib/src/decks/schema11.rs index e54e6654a..7101ea1cb 100644 --- a/rslib/src/decks/schema11.rs +++ b/rslib/src/decks/schema11.rs @@ -362,11 +362,12 @@ impl From for DeckSchema11 { impl From for DeckCommonSchema11 { fn from(deck: Deck) -> Self { - let other: HashMap = if deck.common.other.is_empty() { + let mut other: HashMap = 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 for DeckCommonSchema11 { } } +/// See [crate::deckconfig::schema11::clear_other_duplicates()]. +fn clear_other_duplicates(other: &mut HashMap) { + 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; diff --git a/rslib/src/notetype/schema11.rs b/rslib/src/notetype/schema11.rs index f1e6b9911..5db53d56b 100644 --- a/rslib/src/notetype/schema11.rs +++ b/rslib/src/notetype/schema11.rs @@ -159,8 +159,8 @@ impl From for NotetypeSchema11 { } } +/// See [crate::deckconfig::schema11::clear_other_duplicates()]. fn clear_other_field_duplicates(other: &mut HashMap) { - // see `clear_other_duplicates()` in `deckconfig/schema11.rs` for key in &["description"] { other.remove(*key); }