From dad4c76089728f9ef3ae9baf4e6610d9a4506a53 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 5 Jan 2021 11:07:09 +1000 Subject: [PATCH] no need to log card resets when exporting --- pylib/anki/schedv2.py | 5 ++--- rslib/backend.proto | 7 ++++++- rslib/src/backend/mod.rs | 7 ++++--- rslib/src/sched/new.rs | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 91491ca4d..a34033088 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -1408,7 +1408,7 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""", def schedule_cards_as_new(self, card_ids: List[int]) -> None: "Put cards at the end of the new queue." - self.col.backend.schedule_cards_as_new(card_ids) + self.col.backend.schedule_cards_as_new(card_ids=card_ids, log=True) def schedule_cards_as_reviews( self, card_ids: List[int], min_interval: int, max_interval: int @@ -1432,8 +1432,7 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""", " where id in %s" % sids ) # and forget any non-new cards, changing their due numbers - self.forgetCards(nonNew) - self.col.log(ids) + self.col.backend.schedule_cards_as_new(card_ids=nonNew, log=False) # legacy diff --git a/rslib/backend.proto b/rslib/backend.proto index 675170fb6..ef99ab9ed 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -105,7 +105,7 @@ service BackendService { rpc EmptyFilteredDeck (DeckID) returns (Empty); rpc RebuildFilteredDeck (DeckID) returns (UInt32); rpc ScheduleCardsAsReviews (ScheduleCardsAsReviewsIn) returns (Empty); - rpc ScheduleCardsAsNew (CardIDs) returns (Empty); + rpc ScheduleCardsAsNew (ScheduleCardsAsNewIn) returns (Empty); rpc SortCards (SortCardsIn) returns (Empty); rpc SortDeck (SortDeckIn) returns (Empty); @@ -1068,6 +1068,11 @@ message ScheduleCardsAsReviewsIn { uint32 max_interval = 3; } +message ScheduleCardsAsNewIn { + repeated int64 card_ids = 1; + bool log = 2; +} + message SortCardsIn { repeated int64 card_ids = 1; uint32 starting_from = 2; diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index db4a1802e..e174fe94e 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -565,10 +565,11 @@ impl BackendService for Backend { }) } - fn schedule_cards_as_new(&self, input: pb::CardIDs) -> BackendResult { + fn schedule_cards_as_new(&self, input: pb::ScheduleCardsAsNewIn) -> BackendResult { self.with_col(|col| { - col.reschedule_cards_as_new(&input.into_native()) - .map(Into::into) + let cids: Vec<_> = input.card_ids.into_iter().map(CardID).collect(); + let log = input.log; + col.reschedule_cards_as_new(&cids, log).map(Into::into) }) } diff --git a/rslib/src/sched/new.rs b/rslib/src/sched/new.rs index 4cf7bee3e..ea8737050 100644 --- a/rslib/src/sched/new.rs +++ b/rslib/src/sched/new.rs @@ -68,7 +68,7 @@ impl NewCardSorter { } impl Collection { - pub fn reschedule_cards_as_new(&mut self, cids: &[CardID]) -> Result<()> { + pub fn reschedule_cards_as_new(&mut self, cids: &[CardID], log: bool) -> Result<()> { let usn = self.usn()?; let mut position = self.get_next_card_position(); self.transact(None, |col| { @@ -76,7 +76,9 @@ impl Collection { let cards = col.storage.all_searched_cards_in_search_order()?; for mut card in cards { let original = card.clone(); - col.log_manually_scheduled_review(&card, usn, 0)?; + if log { + col.log_manually_scheduled_review(&card, usn, 0)?; + } card.schedule_as_new(position); col.update_card(&mut card, &original, usn)?; position += 1;