mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
Open transaction in insert_data()
Was slowing down exporting by several orders of magnitude.
This commit is contained in:
parent
98d87fd36a
commit
766396809d
2 changed files with 15 additions and 14 deletions
|
@ -21,7 +21,7 @@ from anki.collection import (
|
|||
)
|
||||
from aqt.errors import show_exception
|
||||
from aqt.qt import QTimer, QWidget, qconnect
|
||||
from aqt.utils import showWarning, tr
|
||||
from aqt.utils import tr
|
||||
|
||||
|
||||
class HasChangesProperty(Protocol):
|
||||
|
|
|
@ -6,37 +6,38 @@ use crate::{prelude::*, revlog::RevlogEntry};
|
|||
|
||||
impl Collection {
|
||||
pub(super) fn insert_data(&mut self, data: &ExchangeData) -> Result<()> {
|
||||
self.insert_decks(&data.decks)?;
|
||||
self.insert_notes(&data.notes)?;
|
||||
self.insert_cards(&data.cards)?;
|
||||
self.insert_notetypes(&data.notetypes)?;
|
||||
self.insert_revlog(&data.revlog)?;
|
||||
self.insert_deck_configs(&data.deck_configs)?;
|
||||
Ok(())
|
||||
self.transact_no_undo(|col| {
|
||||
col.insert_decks(&data.decks)?;
|
||||
col.insert_notes(&data.notes)?;
|
||||
col.insert_cards(&data.cards)?;
|
||||
col.insert_notetypes(&data.notetypes)?;
|
||||
col.insert_revlog(&data.revlog)?;
|
||||
col.insert_deck_configs(&data.deck_configs)
|
||||
})
|
||||
}
|
||||
|
||||
fn insert_decks(&mut self, decks: &[Deck]) -> Result<()> {
|
||||
fn insert_decks(&self, decks: &[Deck]) -> Result<()> {
|
||||
for deck in decks {
|
||||
self.storage.add_or_update_deck_with_existing_id(deck)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_notes(&mut self, notes: &[Note]) -> Result<()> {
|
||||
fn insert_notes(&self, notes: &[Note]) -> Result<()> {
|
||||
for note in notes {
|
||||
self.storage.add_or_update_note(note)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_cards(&mut self, cards: &[Card]) -> Result<()> {
|
||||
fn insert_cards(&self, cards: &[Card]) -> Result<()> {
|
||||
for card in cards {
|
||||
self.storage.add_or_update_card(card)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_notetypes(&mut self, notetypes: &[Notetype]) -> Result<()> {
|
||||
fn insert_notetypes(&self, notetypes: &[Notetype]) -> Result<()> {
|
||||
for notetype in notetypes {
|
||||
self.storage
|
||||
.add_or_update_notetype_with_existing_id(notetype)?;
|
||||
|
@ -44,14 +45,14 @@ impl Collection {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_revlog(&mut self, revlog: &[RevlogEntry]) -> Result<()> {
|
||||
fn insert_revlog(&self, revlog: &[RevlogEntry]) -> Result<()> {
|
||||
for entry in revlog {
|
||||
self.storage.add_revlog_entry(entry, false)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_deck_configs(&mut self, configs: &[DeckConfig]) -> Result<()> {
|
||||
fn insert_deck_configs(&self, configs: &[DeckConfig]) -> Result<()> {
|
||||
for config in configs {
|
||||
self.storage
|
||||
.add_or_update_deck_config_with_existing_id(config)?;
|
||||
|
|
Loading…
Reference in a new issue