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.errors import show_exception
|
||||||
from aqt.qt import QTimer, QWidget, qconnect
|
from aqt.qt import QTimer, QWidget, qconnect
|
||||||
from aqt.utils import showWarning, tr
|
from aqt.utils import tr
|
||||||
|
|
||||||
|
|
||||||
class HasChangesProperty(Protocol):
|
class HasChangesProperty(Protocol):
|
||||||
|
|
|
@ -6,37 +6,38 @@ use crate::{prelude::*, revlog::RevlogEntry};
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub(super) fn insert_data(&mut self, data: &ExchangeData) -> Result<()> {
|
pub(super) fn insert_data(&mut self, data: &ExchangeData) -> Result<()> {
|
||||||
self.insert_decks(&data.decks)?;
|
self.transact_no_undo(|col| {
|
||||||
self.insert_notes(&data.notes)?;
|
col.insert_decks(&data.decks)?;
|
||||||
self.insert_cards(&data.cards)?;
|
col.insert_notes(&data.notes)?;
|
||||||
self.insert_notetypes(&data.notetypes)?;
|
col.insert_cards(&data.cards)?;
|
||||||
self.insert_revlog(&data.revlog)?;
|
col.insert_notetypes(&data.notetypes)?;
|
||||||
self.insert_deck_configs(&data.deck_configs)?;
|
col.insert_revlog(&data.revlog)?;
|
||||||
Ok(())
|
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 {
|
for deck in decks {
|
||||||
self.storage.add_or_update_deck_with_existing_id(deck)?;
|
self.storage.add_or_update_deck_with_existing_id(deck)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_notes(&mut self, notes: &[Note]) -> Result<()> {
|
fn insert_notes(&self, notes: &[Note]) -> Result<()> {
|
||||||
for note in notes {
|
for note in notes {
|
||||||
self.storage.add_or_update_note(note)?;
|
self.storage.add_or_update_note(note)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_cards(&mut self, cards: &[Card]) -> Result<()> {
|
fn insert_cards(&self, cards: &[Card]) -> Result<()> {
|
||||||
for card in cards {
|
for card in cards {
|
||||||
self.storage.add_or_update_card(card)?;
|
self.storage.add_or_update_card(card)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_notetypes(&mut self, notetypes: &[Notetype]) -> Result<()> {
|
fn insert_notetypes(&self, notetypes: &[Notetype]) -> Result<()> {
|
||||||
for notetype in notetypes {
|
for notetype in notetypes {
|
||||||
self.storage
|
self.storage
|
||||||
.add_or_update_notetype_with_existing_id(notetype)?;
|
.add_or_update_notetype_with_existing_id(notetype)?;
|
||||||
|
@ -44,14 +45,14 @@ impl Collection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_revlog(&mut self, revlog: &[RevlogEntry]) -> Result<()> {
|
fn insert_revlog(&self, revlog: &[RevlogEntry]) -> Result<()> {
|
||||||
for entry in revlog {
|
for entry in revlog {
|
||||||
self.storage.add_revlog_entry(entry, false)?;
|
self.storage.add_revlog_entry(entry, false)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_deck_configs(&mut self, configs: &[DeckConfig]) -> Result<()> {
|
fn insert_deck_configs(&self, configs: &[DeckConfig]) -> Result<()> {
|
||||||
for config in configs {
|
for config in configs {
|
||||||
self.storage
|
self.storage
|
||||||
.add_or_update_deck_config_with_existing_id(config)?;
|
.add_or_update_deck_config_with_existing_id(config)?;
|
||||||
|
|
Loading…
Reference in a new issue