mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
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:
parent
6775002709
commit
6622ea1c70
3 changed files with 13 additions and 19 deletions
|
|
@ -14,7 +14,6 @@ from __future__ import annotations
|
||||||
from typing import Tuple, Union
|
from typing import Tuple, Union
|
||||||
|
|
||||||
import anki._backend.backend_pb2 as _pb
|
import anki._backend.backend_pb2 as _pb
|
||||||
from anki import hooks
|
|
||||||
from anki.cards import Card
|
from anki.cards import Card
|
||||||
from anki.consts import *
|
from anki.consts import *
|
||||||
from anki.scheduler.base import CongratsInfo
|
from anki.scheduler.base import CongratsInfo
|
||||||
|
|
@ -23,6 +22,7 @@ from anki.types import assert_exhaustive
|
||||||
from anki.utils import intTime
|
from anki.utils import intTime
|
||||||
|
|
||||||
QueuedCards = _pb.GetQueuedCardsOut.QueuedCards
|
QueuedCards = _pb.GetQueuedCardsOut.QueuedCards
|
||||||
|
SchedulingState = _pb.SchedulingState
|
||||||
|
|
||||||
|
|
||||||
class Scheduler(SchedulerBaseWithLegacy):
|
class Scheduler(SchedulerBaseWithLegacy):
|
||||||
|
|
@ -101,9 +101,7 @@ class Scheduler(SchedulerBaseWithLegacy):
|
||||||
assert 1 <= ease <= 4
|
assert 1 <= ease <= 4
|
||||||
assert 0 <= card.queue <= 4
|
assert 0 <= card.queue <= 4
|
||||||
|
|
||||||
new_state = self._answerCard(card, ease)
|
self._answerCard(card, ease)
|
||||||
|
|
||||||
self._handle_leech(card, new_state)
|
|
||||||
|
|
||||||
self.reps += 1
|
self.reps += 1
|
||||||
|
|
||||||
|
|
@ -138,19 +136,9 @@ class Scheduler(SchedulerBaseWithLegacy):
|
||||||
|
|
||||||
return new_state
|
return new_state
|
||||||
|
|
||||||
def _handle_leech(self, card: Card, new_state: _pb.SchedulingState) -> bool:
|
def state_is_leech(self, new_state: SchedulingState) -> bool:
|
||||||
"True if was leech."
|
"True if new state marks the card as a leech."
|
||||||
if self.col._backend.state_is_leech(new_state):
|
return 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
|
|
||||||
|
|
||||||
# Next times
|
# Next times
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
||||||
|
|
@ -429,7 +429,8 @@ def test_reviews():
|
||||||
|
|
||||||
hooks.card_did_leech.append(onLeech)
|
hooks.card_did_leech.append(onLeech)
|
||||||
col.sched.answerCard(c, 1)
|
col.sched.answerCard(c, 1)
|
||||||
assert hooked
|
if not is_2021():
|
||||||
|
assert hooked
|
||||||
assert c.queue == QUEUE_TYPE_SUSPENDED
|
assert c.queue == QUEUE_TYPE_SUSPENDED
|
||||||
c.load()
|
c.load()
|
||||||
assert c.queue == QUEUE_TYPE_SUSPENDED
|
assert c.queue == QUEUE_TYPE_SUSPENDED
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,12 @@ from hookslib import Hook, write_file
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
hooks = [
|
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="card_odue_was_invalid"),
|
||||||
Hook(name="schema_will_change", args=["proceed: bool"], return_type="bool"),
|
Hook(name="schema_will_change", args=["proceed: bool"], return_type="bool"),
|
||||||
Hook(
|
Hook(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue