mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
always fetch full notetype
This commit is contained in:
parent
527c8bf867
commit
e8f4a75bd5
5 changed files with 30 additions and 28 deletions
|
@ -135,7 +135,7 @@ impl Collection {
|
||||||
self.transact(None, |col| {
|
self.transact(None, |col| {
|
||||||
let nt = col
|
let nt = col
|
||||||
.storage
|
.storage
|
||||||
.get_full_notetype(note.ntid)?
|
.get_notetype(note.ntid)?
|
||||||
.ok_or_else(|| AnkiError::invalid_input("missing note type"))?;
|
.ok_or_else(|| AnkiError::invalid_input("missing note type"))?;
|
||||||
|
|
||||||
let cardgen = CardGenContext::new(&nt, col.usn()?);
|
let cardgen = CardGenContext::new(&nt, col.usn()?);
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl Collection {
|
||||||
self.transact(None, |col| {
|
self.transact(None, |col| {
|
||||||
let existing_notetype = col
|
let existing_notetype = col
|
||||||
.storage
|
.storage
|
||||||
.get_full_notetype(nt.id)?
|
.get_notetype(nt.id)?
|
||||||
.ok_or_else(|| AnkiError::invalid_input("no such notetype"))?;
|
.ok_or_else(|| AnkiError::invalid_input("no such notetype"))?;
|
||||||
col.update_notes_for_changed_fields(nt, existing_notetype.fields.len())?;
|
col.update_notes_for_changed_fields(nt, existing_notetype.fields.len())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -70,7 +70,7 @@ mod test {
|
||||||
let mut col = open_test_collection();
|
let mut col = open_test_collection();
|
||||||
let mut nt = col
|
let mut nt = col
|
||||||
.storage
|
.storage
|
||||||
.get_full_notetype(col.get_current_notetype_id().unwrap())?
|
.get_notetype(col.get_current_notetype_id().unwrap())?
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut note = nt.new_note();
|
let mut note = nt.new_note();
|
||||||
assert_eq!(note.fields.len(), 2);
|
assert_eq!(note.fields.len(), 2);
|
||||||
|
|
|
@ -27,6 +27,17 @@ fn row_to_notetype_core(row: &Row) -> Result<NoteType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SqliteStorage {
|
impl SqliteStorage {
|
||||||
|
pub(crate) fn get_notetype(&self, ntid: NoteTypeID) -> Result<Option<NoteType>> {
|
||||||
|
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<Option<NoteType>> {
|
fn get_notetype_core(&self, ntid: NoteTypeID) -> Result<Option<NoteType>> {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached(concat!(include_str!("get_notetype.sql"), " where id = ?"))?
|
.prepare_cached(concat!(include_str!("get_notetype.sql"), " where id = ?"))?
|
||||||
|
@ -48,6 +59,7 @@ impl SqliteStorage {
|
||||||
Ok(nts)
|
Ok(nts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub as currently used by searching code
|
||||||
pub(crate) fn get_notetype_fields(&self, ntid: NoteTypeID) -> Result<Vec<NoteField>> {
|
pub(crate) fn get_notetype_fields(&self, ntid: NoteTypeID) -> Result<Vec<NoteField>> {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached(include_str!("get_fields.sql"))?
|
.prepare_cached(include_str!("get_fields.sql"))?
|
||||||
|
@ -78,18 +90,7 @@ impl SqliteStorage {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_full_notetype(&self, ntid: NoteTypeID) -> Result<Option<NoteType>> {
|
fn get_notetype_id(&self, name: &str) -> Result<Option<NoteTypeID>> {
|
||||||
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<Option<NoteTypeID>> {
|
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached("select id from notetypes where name = ?")?
|
.prepare_cached("select id from notetypes where name = ?")?
|
||||||
.query_row(params![name], |row| row.get(0))
|
.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<Option<NoteType>> {
|
pub fn get_notetype_by_name(&mut self, name: &str) -> Result<Option<NoteType>> {
|
||||||
if let Some(id) = self.get_notetype_id(name)? {
|
if let Some(id) = self.get_notetype_id(name)? {
|
||||||
self.get_full_notetype(id)
|
self.get_notetype(id)
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -113,17 +114,6 @@ impl SqliteStorage {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_all_notetypes_as_schema11(
|
|
||||||
&self,
|
|
||||||
) -> Result<HashMap<NoteTypeID, NoteTypeSchema11>> {
|
|
||||||
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<()> {
|
fn update_notetype_fields(&self, ntid: NoteTypeID, fields: &[NoteField]) -> Result<()> {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached("delete from fields where ntid=?")?
|
.prepare_cached("delete from fields where ntid=?")?
|
||||||
|
@ -198,7 +188,18 @@ impl SqliteStorage {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upgrading/downgrading
|
// Upgrading/downgrading/legacy
|
||||||
|
|
||||||
|
pub(crate) fn get_all_notetypes_as_schema11(
|
||||||
|
&self,
|
||||||
|
) -> Result<HashMap<NoteTypeID, NoteTypeSchema11>> {
|
||||||
|
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<()> {
|
pub(crate) fn upgrade_notetypes_to_schema15(&self) -> Result<()> {
|
||||||
let nts = self.get_schema11_notetypes()?;
|
let nts = self.get_schema11_notetypes()?;
|
||||||
|
|
|
@ -21,6 +21,7 @@ fn unicase_compare(s1: &str, s2: &str) -> Ordering {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixme: rollback savepoint when tags not changed
|
// 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
|
// currently public for dbproxy
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Reference in a new issue