mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -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) {
|
||||
if self.added_cards.contains(&entry.cid) {
|
||||
entry.usn = self.usn;
|
||||
self.target_col.add_revlog_entry_undoable(entry)?;
|
||||
self.target_col.add_revlog_entry_if_unique_undoable(entry)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -28,9 +28,17 @@ impl Collection {
|
|||
|
||||
/// 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> {
|
||||
entry.id = self.storage.add_revlog_entry(&entry, true)?;
|
||||
entry.id = self.storage.add_revlog_entry(&entry, true)?.unwrap();
|
||||
let id = entry.id;
|
||||
self.save_undo(UndoableRevlogChange::Added(Box::new(entry)));
|
||||
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(())
|
||||
}
|
||||
|
||||
/// 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(
|
||||
&self,
|
||||
entry: &RevlogEntry,
|
||||
ensure_unique: bool,
|
||||
) -> Result<RevlogId> {
|
||||
self.db
|
||||
uniquify: bool,
|
||||
) -> Result<Option<RevlogId>> {
|
||||
let added = self
|
||||
.db
|
||||
.prepare_cached(include_str!("add.sql"))?
|
||||
.execute(params![
|
||||
ensure_unique,
|
||||
uniquify,
|
||||
entry.id,
|
||||
entry.cid,
|
||||
entry.usn,
|
||||
|
@ -81,7 +84,7 @@ impl SqliteStorage {
|
|||
entry.taken_millis,
|
||||
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>> {
|
||||
|
|
Loading…
Reference in a new issue