deckconf -> deckconfig

This commit is contained in:
Damien Elmes 2021-04-20 21:54:24 +10:00
parent 5449198649
commit fd81700679
26 changed files with 78 additions and 75 deletions

View file

@ -5,7 +5,7 @@ use super::Backend;
pub(super) use crate::backend_proto::deckconfig_service::Service as DeckConfigService;
use crate::{
backend_proto as pb,
deckconf::{DeckConf, DeckConfSchema11, UpdateDeckConfigsIn},
deckconfig::{DeckConfSchema11, DeckConfig, UpdateDeckConfigsIn},
prelude::*,
};
@ -15,7 +15,7 @@ impl DeckConfigService for Backend {
input: pb::AddOrUpdateDeckConfigLegacyIn,
) -> Result<pb::DeckConfigId> {
let conf: DeckConfSchema11 = serde_json::from_slice(&input.config)?;
let mut conf: DeckConf = conf.into();
let mut conf: DeckConfig = conf.into();
self.with_col(|col| {
col.transact_no_undo(|col| {
col.add_or_update_deck_config(&mut conf, input.preserve_usn_and_mtime)?;
@ -72,8 +72,8 @@ impl DeckConfigService for Backend {
}
}
impl From<DeckConf> for pb::DeckConfig {
fn from(c: DeckConf) -> Self {
impl From<DeckConfig> for pb::DeckConfig {
fn from(c: DeckConfig) -> Self {
pb::DeckConfig {
id: c.id.0,
name: c.name,
@ -95,9 +95,9 @@ impl From<pb::UpdateDeckConfigsIn> for UpdateDeckConfigsIn {
}
}
impl From<pb::DeckConfig> for DeckConf {
impl From<pb::DeckConfig> for DeckConfig {
fn from(c: pb::DeckConfig) -> Self {
DeckConf {
DeckConfig {
id: c.id.into(),
name: c.name,
mtime_secs: c.mtime_secs.into(),

View file

@ -11,7 +11,7 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::{
collection::Collection,
config::SchedulerVersion,
deckconf::DeckConf,
deckconfig::DeckConfig,
decks::DeckId,
define_newtype,
error::{AnkiError, FilteredDeckError, Result},
@ -278,13 +278,13 @@ impl Collection {
/// Get deck config for the given card. If missing, return default values.
#[allow(dead_code)]
pub(crate) fn deck_config_for_card(&mut self, card: &Card) -> Result<DeckConf> {
pub(crate) fn deck_config_for_card(&mut self, card: &Card) -> Result<DeckConfig> {
if let Some(deck) = self.get_deck(card.original_or_current_deck_id())? {
if let Some(conf_id) = deck.config_id() {
return Ok(self.get_deck_config(conf_id, true)?.unwrap());
}
}
Ok(DeckConf::default())
Ok(DeckConfig::default())
}
}

View file

@ -28,7 +28,7 @@ use crate::{
define_newtype!(DeckConfId, i64);
#[derive(Debug, PartialEq, Clone)]
pub struct DeckConf {
pub struct DeckConfig {
pub id: DeckConfId,
pub name: String,
pub mtime_secs: TimestampSecs,
@ -36,9 +36,9 @@ pub struct DeckConf {
pub inner: DeckConfigInner,
}
impl Default for DeckConf {
impl Default for DeckConfig {
fn default() -> Self {
DeckConf {
DeckConfig {
id: DeckConfId(0),
name: "".to_string(),
mtime_secs: Default::default(),
@ -76,7 +76,7 @@ impl Default for DeckConf {
}
}
impl DeckConf {
impl DeckConfig {
pub(crate) fn set_modified(&mut self, usn: Usn) {
self.mtime_secs = TimestampSecs::now();
self.usn = usn;
@ -85,7 +85,7 @@ impl DeckConf {
impl Collection {
/// If fallback is true, guaranteed to return a deck config.
pub fn get_deck_config(&self, dcid: DeckConfId, fallback: bool) -> Result<Option<DeckConf>> {
pub fn get_deck_config(&self, dcid: DeckConfId, fallback: bool) -> Result<Option<DeckConfig>> {
if let Some(conf) = self.storage.get_deck_config(dcid)? {
return Ok(Some(conf));
}
@ -94,7 +94,7 @@ impl Collection {
return Ok(Some(conf));
}
// if even the default deck config is missing, just return the defaults
Ok(Some(DeckConf::default()))
Ok(Some(DeckConfig::default()))
} else {
Ok(None)
}
@ -104,7 +104,7 @@ impl Collection {
impl Collection {
pub(crate) fn add_or_update_deck_config(
&mut self,
config: &mut DeckConf,
config: &mut DeckConfig,
preserve_usn_and_mtime: bool,
) -> Result<()> {
let usn = if preserve_usn_and_mtime {
@ -128,7 +128,7 @@ impl Collection {
/// usn will be updated.
pub(crate) fn add_deck_config_inner(
&mut self,
config: &mut DeckConf,
config: &mut DeckConfig,
usn: Option<Usn>,
) -> Result<()> {
if let Some(usn) = usn {
@ -142,8 +142,8 @@ impl Collection {
/// and usn will be updated.
pub(crate) fn update_deck_config_inner(
&mut self,
config: &mut DeckConf,
original: DeckConf,
config: &mut DeckConfig,
original: DeckConfig,
usn: Option<Usn>,
) -> Result<()> {
if config == &original {

View file

@ -9,7 +9,7 @@ use serde_json::Value;
use serde_repr::{Deserialize_repr, Serialize_repr};
use serde_tuple::Serialize_tuple;
use super::{DeckConf, DeckConfId, DeckConfigInner, NewCardOrder, INITIAL_EASE_FACTOR_THOUSANDS};
use super::{DeckConfId, DeckConfig, DeckConfigInner, NewCardOrder, INITIAL_EASE_FACTOR_THOUSANDS};
use crate::{serde::default_on_invalid, timestamp::TimestampSecs, types::Usn};
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
@ -214,8 +214,8 @@ impl Default for DeckConfSchema11 {
// schema11 -> schema15
impl From<DeckConfSchema11> for DeckConf {
fn from(mut c: DeckConfSchema11) -> DeckConf {
impl From<DeckConfSchema11> for DeckConfig {
fn from(mut c: DeckConfSchema11) -> DeckConfig {
// merge any json stored in new/rev/lapse into top level
if !c.new.other.is_empty() {
if let Ok(val) = serde_json::to_value(c.new.other) {
@ -238,7 +238,7 @@ impl From<DeckConfSchema11> for DeckConf {
serde_json::to_vec(&c.other).unwrap_or_default()
};
DeckConf {
DeckConfig {
id: c.id,
name: c.name,
mtime_secs: c.mtime,
@ -280,8 +280,8 @@ impl From<DeckConfSchema11> for DeckConf {
}
// latest schema -> schema 11
impl From<DeckConf> for DeckConfSchema11 {
fn from(c: DeckConf) -> DeckConfSchema11 {
impl From<DeckConfig> for DeckConfSchema11 {
fn from(c: DeckConfig) -> DeckConfSchema11 {
// split extra json up
let mut top_other: HashMap<String, Value>;
let mut new_other = Default::default();

View file

@ -6,9 +6,9 @@ use crate::prelude::*;
#[derive(Debug)]
pub(crate) enum UndoableDeckConfigChange {
Added(Box<DeckConf>),
Updated(Box<DeckConf>),
Removed(Box<DeckConf>),
Added(Box<DeckConfig>),
Updated(Box<DeckConfig>),
Removed(Box<DeckConfig>),
}
impl Collection {
@ -29,7 +29,7 @@ impl Collection {
}
}
pub(crate) fn remove_deck_config_undoable(&mut self, config: DeckConf) -> Result<()> {
pub(crate) fn remove_deck_config_undoable(&mut self, config: DeckConfig) -> Result<()> {
self.storage.remove_deck_conf(config.id)?;
self.save_undo(UndoableDeckConfigChange::Removed(Box::new(config)));
Ok(())
@ -37,7 +37,7 @@ impl Collection {
pub(super) fn add_deck_config_undoable(
&mut self,
config: &mut DeckConf,
config: &mut DeckConfig,
) -> Result<(), AnkiError> {
self.storage.add_deck_conf(config)?;
self.save_undo(UndoableDeckConfigChange::Added(Box::new(config.clone())));
@ -46,14 +46,14 @@ impl Collection {
pub(super) fn update_deck_config_undoable(
&mut self,
config: &DeckConf,
original: DeckConf,
config: &DeckConfig,
original: DeckConfig,
) -> Result<()> {
self.save_undo(UndoableDeckConfigChange::Updated(Box::new(original)));
self.storage.update_deck_conf(config)
}
fn restore_deleted_deck_config(&mut self, config: DeckConf) -> Result<()> {
fn restore_deleted_deck_config(&mut self, config: DeckConfig) -> Result<()> {
self.storage
.add_or_update_deck_config_with_existing_id(&config)?;
self.save_undo(UndoableDeckConfigChange::Added(Box::new(config)));

View file

@ -14,7 +14,7 @@ use crate::{
pub struct UpdateDeckConfigsIn {
pub target_deck_id: DeckId,
/// Deck will be set to last provided deck config.
pub configs: Vec<DeckConf>,
pub configs: Vec<DeckConfig>,
pub removed_config_ids: Vec<DeckConfId>,
pub apply_to_children: bool,
}
@ -28,7 +28,7 @@ impl Collection {
Ok(pb::DeckConfigsForUpdate {
all_config: self.get_deck_config_with_extra_for_update()?,
current_deck: Some(self.get_current_deck_for_update(deck)?),
defaults: Some(DeckConf::default().into()),
defaults: Some(DeckConfig::default().into()),
schema_modified: self
.storage
.get_collection_timestamps()?

View file

@ -94,7 +94,7 @@ fn apply_limits(
node: &mut DeckTreeNode,
today: u32,
decks: &HashMap<DeckId, Deck>,
dconf: &HashMap<DeckConfId, DeckConf>,
dconf: &HashMap<DeckConfId, DeckConfig>,
parent_limits: (u32, u32),
) {
let (mut remaining_new, mut remaining_rev) =
@ -128,7 +128,7 @@ fn apply_limits_v2_old(
node: &mut DeckTreeNode,
today: u32,
decks: &HashMap<DeckId, Deck>,
dconf: &HashMap<DeckConfId, DeckConf>,
dconf: &HashMap<DeckConfId, DeckConfig>,
parent_limits: (u32, u32),
) -> u32 {
let original_rev_count = node.review_count;
@ -161,7 +161,7 @@ fn remaining_counts_for_deck(
did: DeckId,
today: u32,
decks: &HashMap<DeckId, Deck>,
dconf: &HashMap<DeckConfId, DeckConf>,
dconf: &HashMap<DeckConfId, DeckConfig>,
) -> (u32, u32) {
if let Some(deck) = decks.get(&did) {
match &deck.kind {
@ -355,7 +355,7 @@ impl Collection {
#[cfg(test)]
mod test {
use super::*;
use crate::{collection::open_test_collection, deckconf::DeckConfId, error::Result};
use crate::{collection::open_test_collection, deckconfig::DeckConfId, error::Result};
#[test]
fn wellformed() -> Result<()> {

View file

@ -12,7 +12,7 @@ pub mod cloze;
pub mod collection;
pub mod config;
pub mod dbcheck;
pub mod deckconf;
pub mod deckconfig;
pub mod decks;
pub mod error;
pub mod findreplace;

View file

@ -11,7 +11,7 @@ use crate::{
card::{Card, CardId},
cloze::add_cloze_numbers_in_string,
collection::Collection,
deckconf::{DeckConf, DeckConfId},
deckconfig::{DeckConfId, DeckConfig},
decks::DeckId,
error::{AnkiError, Result},
notes::{Note, NoteId},
@ -56,7 +56,7 @@ pub(crate) struct CardGenContext<'a> {
#[derive(Default)]
pub(crate) struct CardGenCache {
next_position: Option<u32>,
deck_configs: HashMap<DeckId, DeckConf>,
deck_configs: HashMap<DeckId, DeckConfig>,
}
impl CardGenContext<'_> {
@ -318,8 +318,8 @@ impl Collection {
let next_pos = cache.next_position.unwrap();
match cache.deck_configs.get(&did).unwrap().inner.new_card_order() {
crate::deckconf::NewCardOrder::Random => Ok(random_position(next_pos)),
crate::deckconf::NewCardOrder::Due => Ok(next_pos),
crate::deckconfig::NewCardOrder::Random => Ok(random_position(next_pos)),
crate::deckconfig::NewCardOrder::Due => Ok(next_pos),
}
}

View file

@ -8,7 +8,7 @@ pub use crate::{
card::{Card, CardId},
collection::Collection,
config::BoolKey,
deckconf::{DeckConf, DeckConfId},
deckconfig::{DeckConfId, DeckConfig},
decks::{Deck, DeckId, DeckKind, NativeDeckName},
error::{AnkiError, Result},
i18n::I18n,

View file

@ -21,7 +21,7 @@ use super::{
use crate::{
backend_proto,
card::CardQueue,
deckconf::{DeckConf, LeechAction},
deckconfig::{DeckConfig, LeechAction},
decks::Deck,
prelude::*,
};
@ -50,7 +50,7 @@ pub struct CardAnswer {
struct CardStateUpdater {
card: Card,
deck: Deck,
config: DeckConf,
config: DeckConfig,
timing: SchedTimingToday,
now: TimestampSecs,
fuzz_seed: Option<u64>,
@ -275,7 +275,7 @@ impl Collection {
self.update_queues_after_answering_card(&card, timing)
}
fn maybe_bury_siblings(&mut self, card: &Card, config: &DeckConf) -> Result<()> {
fn maybe_bury_siblings(&mut self, card: &Card, config: &DeckConfig) -> Result<()> {
if config.inner.bury_new || config.inner.bury_reviews {
self.bury_siblings(
card.id,
@ -356,7 +356,7 @@ impl Collection {
&self,
config_id: Option<DeckConfId>,
home_deck_id: DeckId,
) -> Result<DeckConf> {
) -> Result<DeckConfig> {
let config_id = if let Some(config_id) = config_id {
config_id
} else {

View file

@ -6,7 +6,7 @@ mod test {
use crate::{
card::{CardQueue, CardType},
collection::open_test_collection,
deckconf::LeechAction,
deckconfig::LeechAction,
prelude::*,
scheduler::answering::{CardAnswer, Rating},
};

View file

@ -3,7 +3,7 @@
use crate::{
card::{Card, CardQueue, CardType},
deckconf::INITIAL_EASE_FACTOR_THOUSANDS,
deckconfig::INITIAL_EASE_FACTOR_THOUSANDS,
};
impl Card {

View file

@ -19,7 +19,7 @@ use super::{
CardQueues, Counts, LearningQueueEntry, MainQueueEntry, MainQueueEntryKind,
};
use crate::{
deckconf::{NewCardOrder, ReviewCardOrder, ReviewMix},
deckconfig::{NewCardOrder, ReviewCardOrder, ReviewMix},
prelude::*,
};

View file

@ -4,7 +4,7 @@
use std::collections::HashMap;
use super::{Deck, DeckKind};
use crate::deckconf::{DeckConf, DeckConfId};
use crate::deckconfig::{DeckConfId, DeckConfig};
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct RemainingLimits {
@ -13,7 +13,7 @@ pub(crate) struct RemainingLimits {
}
impl RemainingLimits {
pub(crate) fn new(deck: &Deck, config: Option<&DeckConf>, today: u32) -> Self {
pub(crate) fn new(deck: &Deck, config: Option<&DeckConfig>, today: u32) -> Self {
if let Some(config) = config {
let (new_today, rev_today) = deck.new_rev_counts(today);
RemainingLimits {
@ -36,7 +36,7 @@ impl RemainingLimits {
pub(super) fn remaining_limits_capped_to_parents(
decks: &[Deck],
config: &HashMap<DeckConfId, DeckConf>,
config: &HashMap<DeckConfId, DeckConfig>,
today: u32,
) -> Vec<RemainingLimits> {
let mut limits = get_remaining_limits(decks, config, today);
@ -48,7 +48,7 @@ pub(super) fn remaining_limits_capped_to_parents(
/// the provided deck order.
fn get_remaining_limits(
decks: &[Deck],
config: &HashMap<DeckConfId, DeckConf>,
config: &HashMap<DeckConfId, DeckConfig>,
today: u32,
) -> Vec<RemainingLimits> {
decks

View file

@ -9,7 +9,7 @@ use crate::{
card::{Card, CardId, CardQueue, CardType},
collection::Collection,
config::StringKey,
deckconf::INITIAL_EASE_FACTOR_THOUSANDS,
deckconfig::INITIAL_EASE_FACTOR_THOUSANDS,
error::Result,
prelude::*,
};

View file

@ -63,7 +63,7 @@ impl Card {
fn get_filter_info_for_card(
card: &Card,
decks: &HashMap<DeckId, Deck>,
configs: &HashMap<DeckConfId, DeckConf>,
configs: &HashMap<DeckConfId, DeckConfig>,
) -> Option<V1FilteredDeckInfo> {
if card.original_deck_id.0 == 0 {
None

View file

@ -14,7 +14,7 @@ use rusqlite::{
use super::ids_to_string;
use crate::{
card::{Card, CardId, CardQueue, CardType},
deckconf::DeckConfId,
deckconfig::DeckConfId,
decks::{Deck, DeckId, DeckKind},
error::Result,
notes::NoteId,

View file

@ -9,13 +9,13 @@ use serde_json::Value;
use super::SqliteStorage;
use crate::{
deckconf::{DeckConf, DeckConfId, DeckConfSchema11, DeckConfigInner},
deckconfig::{DeckConfId, DeckConfSchema11, DeckConfig, DeckConfigInner},
prelude::*,
};
fn row_to_deckconf(row: &Row) -> Result<DeckConf> {
fn row_to_deckconf(row: &Row) -> Result<DeckConfig> {
let config = DeckConfigInner::decode(row.get_raw(4).as_blob()?)?;
Ok(DeckConf {
Ok(DeckConfig {
id: row.get(0)?,
name: row.get(1)?,
mtime_secs: row.get(2)?,
@ -25,14 +25,14 @@ fn row_to_deckconf(row: &Row) -> Result<DeckConf> {
}
impl SqliteStorage {
pub(crate) fn all_deck_config(&self) -> Result<Vec<DeckConf>> {
pub(crate) fn all_deck_config(&self) -> Result<Vec<DeckConfig>> {
self.db
.prepare_cached(include_str!("get.sql"))?
.query_and_then(NO_PARAMS, row_to_deckconf)?
.collect()
}
pub(crate) fn get_deck_config_map(&self) -> Result<HashMap<DeckConfId, DeckConf>> {
pub(crate) fn get_deck_config_map(&self) -> Result<HashMap<DeckConfId, DeckConfig>> {
self.db
.prepare_cached(include_str!("get.sql"))?
.query_and_then(NO_PARAMS, row_to_deckconf)?
@ -40,7 +40,7 @@ impl SqliteStorage {
.collect()
}
pub(crate) fn get_deck_config(&self, dcid: DeckConfId) -> Result<Option<DeckConf>> {
pub(crate) fn get_deck_config(&self, dcid: DeckConfId) -> Result<Option<DeckConfig>> {
self.db
.prepare_cached(concat!(include_str!("get.sql"), " where id = ?"))?
.query_and_then(params![dcid], row_to_deckconf)?
@ -48,7 +48,7 @@ impl SqliteStorage {
.transpose()
}
pub(crate) fn add_deck_conf(&self, conf: &mut DeckConf) -> Result<()> {
pub(crate) fn add_deck_conf(&self, conf: &mut DeckConfig) -> Result<()> {
let mut conf_bytes = vec![];
conf.inner.encode(&mut conf_bytes)?;
self.db
@ -67,7 +67,7 @@ impl SqliteStorage {
Ok(())
}
pub(crate) fn update_deck_conf(&self, conf: &DeckConf) -> Result<()> {
pub(crate) fn update_deck_conf(&self, conf: &DeckConfig) -> Result<()> {
let mut conf_bytes = vec![];
conf.inner.encode(&mut conf_bytes)?;
self.db
@ -84,7 +84,10 @@ impl SqliteStorage {
/// Used for syncing&undo; will keep provided ID. Shouldn't be used to add
/// new config normally, since it does not allocate an id.
pub(crate) fn add_or_update_deck_config_with_existing_id(&self, conf: &DeckConf) -> Result<()> {
pub(crate) fn add_or_update_deck_config_with_existing_id(
&self,
conf: &DeckConfig,
) -> Result<()> {
if conf.id.0 == 0 {
return Err(AnkiError::invalid_input("deck with id 0"));
}
@ -119,7 +122,7 @@ impl SqliteStorage {
// Creating/upgrading/downgrading
pub(super) fn add_default_deck_config(&self, tr: &I18n) -> Result<()> {
let mut conf = DeckConf::default();
let mut conf = DeckConfig::default();
conf.id.0 = 1;
conf.name = tr.deck_config_default_name().into();
self.add_deck_conf(&mut conf)
@ -180,7 +183,7 @@ impl SqliteStorage {
pub(super) fn upgrade_deck_conf_to_schema15(&self) -> Result<()> {
for conf in self.all_deck_config_schema14()? {
let mut conf: DeckConf = conf.into();
let mut conf: DeckConfig = conf.into();
// schema 15 stored starting ease of 2.5 as 250
conf.inner.initial_ease *= 100.0;
self.update_deck_conf(&conf)?;

View file

@ -5,7 +5,7 @@ pub(crate) mod card;
mod collection_timestamps;
mod config;
mod deck;
mod deckconf;
mod deckconfig;
mod graves;
mod note;
mod notetype;

View file

@ -18,7 +18,7 @@ pub(crate) use server::{LocalServer, SyncServer};
use crate::{
backend_proto::{sync_status_out, SyncStatusOut},
card::{Card, CardQueue, CardType},
deckconf::DeckConfSchema11,
deckconfig::DeckConfSchema11,
decks::DeckSchema11,
error::{SyncError, SyncErrorKind},
notes::Note,
@ -1200,7 +1200,7 @@ mod test {
use super::{server::LocalServer, *};
use crate::{
collection::open_collection, deckconf::DeckConf, decks::DeckKind, i18n::I18n, log,
collection::open_collection, deckconfig::DeckConfig, decks::DeckKind, i18n::I18n, log,
notetype::all_stock_notetypes, search::SortMode,
};
@ -1374,7 +1374,7 @@ mod test {
let mut deck = col1.get_or_create_normal_deck("new deck")?;
// give it a new option group
let mut dconf = DeckConf {
let mut dconf = DeckConfig {
name: "new dconf".into(),
..Default::default()
};

View file

@ -3,7 +3,7 @@
use crate::{
card::undo::UndoableCardChange, collection::undo::UndoableCollectionChange,
config::undo::UndoableConfigChange, deckconf::undo::UndoableDeckConfigChange,
config::undo::UndoableConfigChange, deckconfig::undo::UndoableDeckConfigChange,
decks::undo::UndoableDeckChange, notes::undo::UndoableNoteChange, prelude::*,
revlog::undo::UndoableRevlogChange, scheduler::queue::undo::UndoableQueueChange,
tags::undo::UndoableTagChange,