tidy up sibling burying

closes #649
This commit is contained in:
Damien Elmes 2020-06-01 13:48:15 +10:00
parent 8516ed8655
commit 6204a86879
2 changed files with 9 additions and 55 deletions

View file

@ -859,47 +859,3 @@ update cards set queue={QUEUE_TYPE_SIBLING_BURIED},mod=?,usn=? where id in """
intTime(), intTime(),
self.col.usn(), self.col.usn(),
) )
# Sibling spacing
##########################################################################
def _burySiblings(self, card: Card) -> None:
toBury = []
nconf = self._newConf(card)
buryNew = nconf.get("bury", True)
rconf = self._revConf(card)
buryRev = rconf.get("bury", True)
# loop through and remove from queues
for cid, queue in self.col.db.execute(
f"""
select id, queue from cards where nid=? and id!=?
and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
card.nid,
card.id,
self.today,
):
if queue == QUEUE_TYPE_REV:
if buryRev:
toBury.append(cid)
# if bury disabled, we still discard to give same-day spacing
try:
self._revQueue.remove(cid)
except ValueError:
pass
else:
# if bury disabled, we still discard to give same-day spacing
if buryNew:
toBury.append(cid)
try:
self._newQueue.remove(cid)
except ValueError:
pass
# then bury
if toBury:
self.col.db.execute(
f"update cards set queue={QUEUE_TYPE_SIBLING_BURIED},mod=?,usn=? where id in "
+ ids2str(toBury),
intTime(),
self.col.usn(),
)
self.col.log(toBury)

View file

@ -1523,7 +1523,7 @@ update cards set queue=?,mod=?,usn=? where id in """
########################################################################## ##########################################################################
def _burySiblings(self, card: Card) -> None: def _burySiblings(self, card: Card) -> None:
toBury = [] toBury: List[int] = []
nconf = self._newConf(card) nconf = self._newConf(card)
buryNew = nconf.get("bury", True) buryNew = nconf.get("bury", True)
rconf = self._revConf(card) rconf = self._revConf(card)
@ -1538,21 +1538,19 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
self.today, self.today,
): ):
if queue == QUEUE_TYPE_REV: if queue == QUEUE_TYPE_REV:
queue_obj = self._revQueue
if buryRev: if buryRev:
toBury.append(cid) toBury.append(cid)
# if bury disabled, we still discard to give same-day spacing
try:
self._revQueue.remove(cid)
except ValueError:
pass
else: else:
# if bury disabled, we still discard to give same-day spacing queue_obj = self._newQueue
if buryNew: if buryNew:
toBury.append(cid) toBury.append(cid)
try:
self._newQueue.remove(cid) # even if burying disabled, we still discard to give same-day spacing
except ValueError: try:
pass queue_obj.remove(cid)
except ValueError:
pass
# then bury # then bury
if toBury: if toBury:
self.buryCards(toBury, manual=False) self.buryCards(toBury, manual=False)