drop leech hook in test scheduler

The explicit flush was clearing undo history, and the hook will need
re-working to support propagating OpChanges correctly. It will likely
come back as a GUI hook, instead of one in pylib.
This commit is contained in:
Damien Elmes 2021-05-10 15:05:52 +10:00
parent 6775002709
commit 6622ea1c70
3 changed files with 13 additions and 19 deletions

View File

@ -14,7 +14,6 @@ from __future__ import annotations
from typing import Tuple, Union
import anki._backend.backend_pb2 as _pb
from anki import hooks
from anki.cards import Card
from anki.consts import *
from anki.scheduler.base import CongratsInfo
@ -23,6 +22,7 @@ from anki.types import assert_exhaustive
from anki.utils import intTime
QueuedCards = _pb.GetQueuedCardsOut.QueuedCards
SchedulingState = _pb.SchedulingState
class Scheduler(SchedulerBaseWithLegacy):
@ -101,9 +101,7 @@ class Scheduler(SchedulerBaseWithLegacy):
assert 1 <= ease <= 4
assert 0 <= card.queue <= 4
new_state = self._answerCard(card, ease)
self._handle_leech(card, new_state)
self._answerCard(card, ease)
self.reps += 1
@ -138,19 +136,9 @@ class Scheduler(SchedulerBaseWithLegacy):
return new_state
def _handle_leech(self, card: Card, new_state: _pb.SchedulingState) -> bool:
"True if was leech."
if self.col._backend.state_is_leech(new_state):
if hooks.card_did_leech.count() > 0:
hooks.card_did_leech(card)
# leech hooks assumed that card mutations would be saved for them
card.mod = intTime()
card.usn = self.col.usn()
card.flush()
return True
else:
return False
def state_is_leech(self, new_state: SchedulingState) -> bool:
"True if new state marks the card as a leech."
return self.col._backend.state_is_leech(new_state)
# Next times
##########################################################################

View File

@ -429,7 +429,8 @@ def test_reviews():
hooks.card_did_leech.append(onLeech)
col.sched.answerCard(c, 1)
assert hooked
if not is_2021():
assert hooked
assert c.queue == QUEUE_TYPE_SUSPENDED
c.load()
assert c.queue == QUEUE_TYPE_SUSPENDED

View File

@ -18,7 +18,12 @@ from hookslib import Hook, write_file
######################################################################
hooks = [
Hook(name="card_did_leech", args=["card: Card"], legacy_hook="leech"),
Hook(
name="card_did_leech",
args=["card: Card"],
legacy_hook="leech",
doc="Called by v1/v2 scheduler when a card is marked as a leech.",
),
Hook(name="card_odue_was_invalid"),
Hook(name="schema_will_change", args=["proceed: bool"], return_type="bool"),
Hook(