mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Keep source ids of imported revlog (or skip)
This commit is contained in:
parent
a0604a2e51
commit
5a76d2211a
3 changed files with 19 additions and 8 deletions
|
@ -434,7 +434,7 @@ impl<'a> Context<'a> {
|
||||||
for mut entry in mem::take(&mut self.data.revlog) {
|
for mut entry in mem::take(&mut self.data.revlog) {
|
||||||
if self.added_cards.contains(&entry.cid) {
|
if self.added_cards.contains(&entry.cid) {
|
||||||
entry.usn = self.usn;
|
entry.usn = self.usn;
|
||||||
self.target_col.add_revlog_entry_undoable(entry)?;
|
self.target_col.add_revlog_entry_if_unique_undoable(entry)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -28,9 +28,17 @@ impl Collection {
|
||||||
|
|
||||||
/// Add the provided revlog entry, modifying the ID if it is not unique.
|
/// Add the provided revlog entry, modifying the ID if it is not unique.
|
||||||
pub(crate) fn add_revlog_entry_undoable(&mut self, mut entry: RevlogEntry) -> Result<RevlogId> {
|
pub(crate) fn add_revlog_entry_undoable(&mut self, mut entry: RevlogEntry) -> Result<RevlogId> {
|
||||||
entry.id = self.storage.add_revlog_entry(&entry, true)?;
|
entry.id = self.storage.add_revlog_entry(&entry, true)?.unwrap();
|
||||||
let id = entry.id;
|
let id = entry.id;
|
||||||
self.save_undo(UndoableRevlogChange::Added(Box::new(entry)));
|
self.save_undo(UndoableRevlogChange::Added(Box::new(entry)));
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add the provided revlog entry, if its ID is unique.
|
||||||
|
pub(crate) fn add_revlog_entry_if_unique_undoable(&mut self, entry: RevlogEntry) -> Result<()> {
|
||||||
|
if self.storage.add_revlog_entry(&entry, false)?.is_some() {
|
||||||
|
self.save_undo(UndoableRevlogChange::Added(Box::new(entry)));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,16 +61,19 @@ impl SqliteStorage {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the used id, which may differ if `ensure_unique` is true.
|
/// Adds the entry, if its id is unique. If it is not, and `uniquify` is true,
|
||||||
|
/// adds it with a new id. Returns the added id.
|
||||||
|
/// (I.e., the option is safe to unwrap, if `uniquify` is true.)
|
||||||
pub(crate) fn add_revlog_entry(
|
pub(crate) fn add_revlog_entry(
|
||||||
&self,
|
&self,
|
||||||
entry: &RevlogEntry,
|
entry: &RevlogEntry,
|
||||||
ensure_unique: bool,
|
uniquify: bool,
|
||||||
) -> Result<RevlogId> {
|
) -> Result<Option<RevlogId>> {
|
||||||
self.db
|
let added = self
|
||||||
|
.db
|
||||||
.prepare_cached(include_str!("add.sql"))?
|
.prepare_cached(include_str!("add.sql"))?
|
||||||
.execute(params![
|
.execute(params![
|
||||||
ensure_unique,
|
uniquify,
|
||||||
entry.id,
|
entry.id,
|
||||||
entry.cid,
|
entry.cid,
|
||||||
entry.usn,
|
entry.usn,
|
||||||
|
@ -81,7 +84,7 @@ impl SqliteStorage {
|
||||||
entry.taken_millis,
|
entry.taken_millis,
|
||||||
entry.review_kind as u8
|
entry.review_kind as u8
|
||||||
])?;
|
])?;
|
||||||
Ok(RevlogId(self.db.last_insert_rowid()))
|
Ok((added > 0).then(|| RevlogId(self.db.last_insert_rowid())))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_revlog_entry(&self, id: RevlogId) -> Result<Option<RevlogEntry>> {
|
pub(crate) fn get_revlog_entry(&self, id: RevlogId) -> Result<Option<RevlogEntry>> {
|
||||||
|
|
Loading…
Reference in a new issue