diff --git a/rslib/src/notes.rs b/rslib/src/notes.rs index b28c585e8..750a6dbb3 100644 --- a/rslib/src/notes.rs +++ b/rslib/src/notes.rs @@ -135,7 +135,7 @@ impl Collection { self.transact(None, |col| { let nt = col .storage - .get_full_notetype(note.ntid)? + .get_notetype(note.ntid)? .ok_or_else(|| AnkiError::invalid_input("missing note type"))?; let cardgen = CardGenContext::new(&nt, col.usn()?); diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index f6cba7f34..d5ad7a583 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -197,7 +197,7 @@ impl Collection { self.transact(None, |col| { let existing_notetype = col .storage - .get_full_notetype(nt.id)? + .get_notetype(nt.id)? .ok_or_else(|| AnkiError::invalid_input("no such notetype"))?; col.update_notes_for_changed_fields(nt, existing_notetype.fields.len())?; Ok(()) diff --git a/rslib/src/notetype/schemachange.rs b/rslib/src/notetype/schemachange.rs index 6f6dce076..1c69deedd 100644 --- a/rslib/src/notetype/schemachange.rs +++ b/rslib/src/notetype/schemachange.rs @@ -70,7 +70,7 @@ mod test { let mut col = open_test_collection(); let mut nt = col .storage - .get_full_notetype(col.get_current_notetype_id().unwrap())? + .get_notetype(col.get_current_notetype_id().unwrap())? .unwrap(); let mut note = nt.new_note(); assert_eq!(note.fields.len(), 2); diff --git a/rslib/src/storage/notetype/mod.rs b/rslib/src/storage/notetype/mod.rs index 12ac3f48d..b5b7734c7 100644 --- a/rslib/src/storage/notetype/mod.rs +++ b/rslib/src/storage/notetype/mod.rs @@ -27,6 +27,17 @@ fn row_to_notetype_core(row: &Row) -> Result { } impl SqliteStorage { + pub(crate) fn get_notetype(&self, ntid: NoteTypeID) -> Result> { + match self.get_notetype_core(ntid)? { + Some(mut nt) => { + nt.fields = self.get_notetype_fields(ntid)?; + nt.templates = self.get_notetype_templates(ntid)?; + Ok(Some(nt)) + } + None => Ok(None), + } + } + fn get_notetype_core(&self, ntid: NoteTypeID) -> Result> { self.db .prepare_cached(concat!(include_str!("get_notetype.sql"), " where id = ?"))? @@ -48,6 +59,7 @@ impl SqliteStorage { Ok(nts) } + // pub as currently used by searching code pub(crate) fn get_notetype_fields(&self, ntid: NoteTypeID) -> Result> { self.db .prepare_cached(include_str!("get_fields.sql"))? @@ -78,18 +90,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_full_notetype(&self, ntid: NoteTypeID) -> Result> { - match self.get_notetype_core(ntid)? { - Some(mut nt) => { - nt.fields = self.get_notetype_fields(ntid)?; - nt.templates = self.get_notetype_templates(ntid)?; - Ok(Some(nt)) - } - None => Ok(None), - } - } - - pub(crate) fn get_notetype_id(&self, name: &str) -> Result> { + fn get_notetype_id(&self, name: &str) -> Result> { self.db .prepare_cached("select id from notetypes where name = ?")? .query_row(params![name], |row| row.get(0)) @@ -99,7 +100,7 @@ impl SqliteStorage { pub fn get_notetype_by_name(&mut self, name: &str) -> Result> { if let Some(id) = self.get_notetype_id(name)? { - self.get_full_notetype(id) + self.get_notetype(id) } else { Ok(None) } @@ -113,17 +114,6 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_all_notetypes_as_schema11( - &self, - ) -> Result> { - let mut nts = HashMap::new(); - for (ntid, _name) in self.get_all_notetype_core()? { - let full = self.get_full_notetype(ntid)?.unwrap(); - nts.insert(ntid, full.into()); - } - Ok(nts) - } - fn update_notetype_fields(&self, ntid: NoteTypeID, fields: &[NoteField]) -> Result<()> { self.db .prepare_cached("delete from fields where ntid=?")? @@ -198,7 +188,18 @@ impl SqliteStorage { Ok(()) } - // Upgrading/downgrading + // Upgrading/downgrading/legacy + + pub(crate) fn get_all_notetypes_as_schema11( + &self, + ) -> Result> { + let mut nts = HashMap::new(); + for (ntid, _name) in self.get_all_notetype_names()? { + let full = self.get_notetype(ntid)?.unwrap(); + nts.insert(ntid, full.into()); + } + Ok(nts) + } pub(crate) fn upgrade_notetypes_to_schema15(&self) -> Result<()> { let nts = self.get_schema11_notetypes()?; diff --git a/rslib/src/storage/sqlite.rs b/rslib/src/storage/sqlite.rs index da4878db7..bd4d4497a 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -21,6 +21,7 @@ fn unicase_compare(s1: &str, s2: &str) -> Ordering { } // fixme: rollback savepoint when tags not changed +// fixme: need to drop out of wal prior to vacuuming to fix page size of older collections // currently public for dbproxy #[derive(Debug)]