rework and merge updateCutoff
- the old "mutate but don't save" approach to resetting the "done today" counts no longer works, and was inefficient anyway - now we just check the day when returning the count - remove separate implementation for v1 scheduler This is a stop-gap solution - a bigger refactor will need to wait until the deck/note type changes have stabilized.
This commit is contained in:
parent
bd1ce123af
commit
2efda14200
@ -113,7 +113,6 @@ class Scheduler(V2):
|
|||||||
|
|
||||||
def unburyCards(self) -> None:
|
def unburyCards(self) -> None:
|
||||||
"Unbury cards."
|
"Unbury cards."
|
||||||
self.col.conf["lastUnburied"] = self.today
|
|
||||||
self.col.log(
|
self.col.log(
|
||||||
self.col.db.list(
|
self.col.db.list(
|
||||||
f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED}"
|
f"select id from cards where queue = {QUEUE_TYPE_SIBLING_BURIED}"
|
||||||
@ -448,7 +447,7 @@ and due <= ? limit ?)""",
|
|||||||
if d["dyn"]:
|
if d["dyn"]:
|
||||||
return self.reportLimit
|
return self.reportLimit
|
||||||
c = self.col.decks.confForDid(d["id"])
|
c = self.col.decks.confForDid(d["id"])
|
||||||
limit = max(0, c["rev"]["perDay"] - d["revToday"][1])
|
limit = max(0, c["rev"]["perDay"] - self._update_stats(d, "rev", 0))
|
||||||
return hooks.scheduler_review_limit_for_single_deck(limit, d)
|
return hooks.scheduler_review_limit_for_single_deck(limit, d)
|
||||||
|
|
||||||
def _revForDeck(self, did: int, lim: int) -> int: # type: ignore[override]
|
def _revForDeck(self, did: int, lim: int) -> int: # type: ignore[override]
|
||||||
@ -785,31 +784,6 @@ did = ?, queue = %s, due = ?, usn = ? where id = ?"""
|
|||||||
return True
|
return True
|
||||||
return conf["resched"]
|
return conf["resched"]
|
||||||
|
|
||||||
# Daily cutoff
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
def _updateCutoff(self) -> None:
|
|
||||||
oldToday = self.today
|
|
||||||
timing = self._timing_today()
|
|
||||||
self.today = timing.days_elapsed
|
|
||||||
self.dayCutoff = timing.next_day_at
|
|
||||||
if oldToday != self.today:
|
|
||||||
self.col.log(self.today, self.dayCutoff)
|
|
||||||
# update all daily counts, but don't save decks to prevent needless
|
|
||||||
# conflicts. we'll save on card answer instead
|
|
||||||
def update(g):
|
|
||||||
for t in "new", "rev", "lrn", "time":
|
|
||||||
key = t + "Today"
|
|
||||||
if g[key][0] != self.today:
|
|
||||||
g[key] = [self.today, 0]
|
|
||||||
|
|
||||||
for deck in self.col.decks.all():
|
|
||||||
update(deck)
|
|
||||||
# unbury if the day has rolled over
|
|
||||||
unburied = self.col.conf.get("lastUnburied", 0)
|
|
||||||
if unburied < self.today:
|
|
||||||
self.unburyCards()
|
|
||||||
|
|
||||||
# Deck finished state
|
# Deck finished state
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -172,12 +172,18 @@ order by due"""
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def _updateStats(self, card: Card, type: str, cnt: int = 1) -> None:
|
def _updateStats(self, card: Card, type: str, cnt: int = 1) -> None:
|
||||||
key = type + "Today"
|
|
||||||
for g in [self.col.decks.get(card.did)] + self.col.decks.parents(card.did):
|
for g in [self.col.decks.get(card.did)] + self.col.decks.parents(card.did):
|
||||||
# add
|
self._update_stats(g, type, cnt)
|
||||||
g[key][1] += cnt
|
|
||||||
self.col.decks.save(g)
|
self.col.decks.save(g)
|
||||||
|
|
||||||
|
# resets stat if day has changed, applies delta, and returns modified value
|
||||||
|
def _update_stats(self, deck: Dict, type: str, delta: int) -> int:
|
||||||
|
key = type + "Today"
|
||||||
|
if deck[key][0] != self.today:
|
||||||
|
deck[key] = [self.today, 0]
|
||||||
|
deck[key][1] += delta
|
||||||
|
return deck[key][1]
|
||||||
|
|
||||||
def extendLimits(self, new: int, rev: int) -> None:
|
def extendLimits(self, new: int, rev: int) -> None:
|
||||||
cur = self.col.decks.current()
|
cur = self.col.decks.current()
|
||||||
parents = self.col.decks.parents(cur["id"])
|
parents = self.col.decks.parents(cur["id"])
|
||||||
@ -186,9 +192,8 @@ order by due"""
|
|||||||
for (name, did) in self.col.decks.children(cur["id"])
|
for (name, did) in self.col.decks.children(cur["id"])
|
||||||
]
|
]
|
||||||
for g in [cur] + parents + children:
|
for g in [cur] + parents + children:
|
||||||
# add
|
self._update_stats(g, "new", -new)
|
||||||
g["newToday"][1] -= new
|
self._update_stats(g, "rev", -rev)
|
||||||
g["revToday"][1] -= rev
|
|
||||||
self.col.decks.save(g)
|
self.col.decks.save(g)
|
||||||
|
|
||||||
def _walkingCount(
|
def _walkingCount(
|
||||||
@ -394,7 +399,7 @@ select count() from
|
|||||||
if g["dyn"]:
|
if g["dyn"]:
|
||||||
return self.dynReportLimit
|
return self.dynReportLimit
|
||||||
c = self.col.decks.confForDid(g["id"])
|
c = self.col.decks.confForDid(g["id"])
|
||||||
limit = max(0, c["new"]["perDay"] - g["newToday"][1])
|
limit = max(0, c["new"]["perDay"] - self._update_stats(g, "new", 0))
|
||||||
return hooks.scheduler_new_limit_for_single_deck(limit, g)
|
return hooks.scheduler_new_limit_for_single_deck(limit, g)
|
||||||
|
|
||||||
def totalNewForCurrentDeck(self) -> int:
|
def totalNewForCurrentDeck(self) -> int:
|
||||||
@ -787,7 +792,7 @@ and due <= ? limit ?)""",
|
|||||||
return self.dynReportLimit
|
return self.dynReportLimit
|
||||||
|
|
||||||
c = self.col.decks.confForDid(d["id"])
|
c = self.col.decks.confForDid(d["id"])
|
||||||
lim = max(0, c["rev"]["perDay"] - d["revToday"][1])
|
lim = max(0, c["rev"]["perDay"] - self._update_stats(d, "rev", 0))
|
||||||
|
|
||||||
if parentLimit is not None:
|
if parentLimit is not None:
|
||||||
lim = min(parentLimit, lim)
|
lim = min(parentLimit, lim)
|
||||||
@ -1278,19 +1283,6 @@ where id = ?
|
|||||||
self.today = timing.days_elapsed
|
self.today = timing.days_elapsed
|
||||||
self.dayCutoff = timing.next_day_at
|
self.dayCutoff = timing.next_day_at
|
||||||
|
|
||||||
if oldToday != self.today:
|
|
||||||
self.col.log(self.today, self.dayCutoff)
|
|
||||||
|
|
||||||
# update all daily counts, but don't save decks to prevent needless
|
|
||||||
# conflicts. we'll save on card answer instead
|
|
||||||
def update(g):
|
|
||||||
for t in "new", "rev", "lrn", "time":
|
|
||||||
key = t + "Today"
|
|
||||||
if g[key][0] != self.today:
|
|
||||||
g[key] = [self.today, 0]
|
|
||||||
|
|
||||||
for deck in self.col.decks.all():
|
|
||||||
update(deck)
|
|
||||||
# unbury if the day has rolled over
|
# unbury if the day has rolled over
|
||||||
unburied = self.col.conf.get("lastUnburied", 0)
|
unburied = self.col.conf.get("lastUnburied", 0)
|
||||||
if unburied < self.today:
|
if unburied < self.today:
|
||||||
|
Loading…
Reference in New Issue
Block a user