mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 09:16:38 -04:00
mod schema if field/templates changed
Instead of throwing an error if schema not marked as changed, just mark it changed, as that way it can be included as part of the same transaction.
This commit is contained in:
parent
f86c2dc567
commit
b89dd32f78
7 changed files with 12 additions and 19 deletions
|
@ -75,7 +75,6 @@ fn anki_error_to_proto_error(err: AnkiError, i18n: &I18n) -> pb::BackendError {
|
|||
AnkiError::Interrupted => V::Interrupted(Empty {}),
|
||||
AnkiError::CollectionNotOpen => V::InvalidInput(pb::Empty {}),
|
||||
AnkiError::CollectionAlreadyOpen => V::InvalidInput(pb::Empty {}),
|
||||
AnkiError::SchemaChange => V::InvalidInput(pb::Empty {}),
|
||||
AnkiError::JSONError { info } => V::JsonError(info),
|
||||
AnkiError::ProtoError { info } => V::ProtoError(info),
|
||||
};
|
||||
|
|
|
@ -172,14 +172,6 @@ impl Collection {
|
|||
self.storage.usn(self.server)
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_schema_modified(&self) -> Result<()> {
|
||||
if !self.storage.schema_modified()? {
|
||||
Err(AnkiError::SchemaChange)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn before_upload(&self) -> Result<()> {
|
||||
self.storage.clear_tag_usns()?;
|
||||
self.storage.clear_deck_conf_usns()?;
|
||||
|
|
|
@ -234,11 +234,12 @@ impl Collection {
|
|||
}
|
||||
}
|
||||
|
||||
/// Remove a deck configuration. This will force a full sync.
|
||||
pub(crate) fn remove_deck_config(&self, dcid: DeckConfID) -> Result<()> {
|
||||
if dcid.0 == 1 {
|
||||
return Err(AnkiError::invalid_input("can't delete default conf"));
|
||||
}
|
||||
self.ensure_schema_modified()?;
|
||||
self.storage.set_schema_modified()?;
|
||||
self.storage.remove_deck_conf(dcid)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,6 @@ pub enum AnkiError {
|
|||
|
||||
#[fail(display = "Close the existing collection first.")]
|
||||
CollectionAlreadyOpen,
|
||||
|
||||
#[fail(display = "Operation modifies schema, but schema not marked modified.")]
|
||||
SchemaChange,
|
||||
}
|
||||
|
||||
// error helpers
|
||||
|
|
|
@ -205,6 +205,8 @@ impl From<NoteType> for NoteTypeProto {
|
|||
}
|
||||
|
||||
impl Collection {
|
||||
/// Saves changes to a note type. This will force a full sync if templates
|
||||
/// or fields have been added/removed/reordered.
|
||||
pub fn update_notetype(&mut self, nt: &mut NoteType) -> Result<()> {
|
||||
self.transact(None, |col| {
|
||||
let existing_notetype = col
|
||||
|
|
|
@ -61,6 +61,8 @@ impl Collection {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
self.storage.set_schema_modified()?;
|
||||
|
||||
let nids = self.search_notes_only(&format!("mid:{}", nt.id))?;
|
||||
let usn = self.usn()?;
|
||||
for nid in nids {
|
||||
|
@ -99,6 +101,8 @@ impl Collection {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
self.storage.set_schema_modified()?;
|
||||
|
||||
let changes = TemplateOrdChanges::new(ords, previous_template_count as u32);
|
||||
if !changes.removed.is_empty() {
|
||||
self.storage
|
||||
|
@ -239,5 +243,3 @@ mod test {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// fixme: make sure we don't orphan notes
|
||||
|
|
|
@ -294,10 +294,10 @@ impl SqliteStorage {
|
|||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub(crate) fn schema_modified(&self) -> Result<bool> {
|
||||
pub(crate) fn set_schema_modified(&self) -> Result<()> {
|
||||
self.db
|
||||
.prepare_cached("select scm > ls from col")?
|
||||
.query_row(NO_PARAMS, |row| row.get(0))
|
||||
.map_err(Into::into)
|
||||
.prepare_cached("update col set scm = ?")?
|
||||
.execute(&[TimestampMillis::now()])?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue