Skip to content

Commit

Permalink
Feat/clear manual rescheduling logs (open-spaced-repetition#488)
Browse files Browse the repository at this point in the history
Co-authored-by: user1823 <[email protected]>
  • Loading branch information
L-M-Sherlock and user1823 authored Nov 15, 2024
1 parent 238dd2d commit 7830911
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
9 changes: 7 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .schedule.postpone import postpone
from .schedule.advance import advance
from .schedule.flatten import flatten
from .schedule.reset import clear_custom_data
from .schedule.reset import clear_custom_data, clear_manual_rescheduling
from .schedule.disperse_siblings import disperse_siblings
from .schedule.easy_days import (
easy_days,
Expand Down Expand Up @@ -179,6 +179,10 @@ def reschedule_recent(did):

menu_reset = build_action(clear_custom_data, "Clear custom data in all cards")

menu_clear_manual_rescheduling = build_action(
clear_manual_rescheduling, "Delete redundant manual revlog entries"
)

menu_disperse_siblings = build_action(disperse_siblings, "Disperse all siblings")

menu_remedy_hard_misuse = build_action(remedy_hard_misuse, "Remedy")
Expand Down Expand Up @@ -244,9 +248,10 @@ def sponsor(did=None):
menu_for_helper.addAction(menu_postpone)
menu_for_helper.addAction(menu_advance)
menu_for_helper.addAction(menu_flatten)
menu_for_helper.addAction(menu_reset)
menu_for_helper.addAction(menu_disperse_siblings)
menu_for_helper.addSeparator()
menu_for_helper.addAction(menu_reset)
menu_for_helper.addAction(menu_clear_manual_rescheduling)
menu_for_remedy = menu_for_helper.addMenu("Remedy Hard Misuse")
menu_for_remedy.addAction(menu_remedy_hard_misuse)
menu_for_remedy.addAction(menu_undo_remedy)
Expand Down
37 changes: 37 additions & 0 deletions schedule/reset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ..utils import *
from anki.utils import ids2str


def clear_custom_data(did):
Expand Down Expand Up @@ -33,3 +34,39 @@ def clear_custom_data(did):
mw.col.merge_undo_entries(undo_entry)
tooltip(f"""{cnt} cards cleared in {time.time() - start_time:.2f} seconds.""")
mw.reset()


def clear_manual_rescheduling(did):
if not askUser(
'This option removes revlog entries generated by "Set due date" and "Reschedule cards on change" '
+ "that immediately precede another manual or reschedule entry.\n\n"
+ "This action cannot be undone. Do you want to continue?"
):
return

if not ask_one_way_sync():
return

revlog_ids = mw.col.db.list(
"""
SELECT cur.id
FROM revlog as cur
WHERE cur.type >= 4
AND cur.factor <> 0
AND (
SELECT type
FROM revlog
WHERE id = (
SELECT min(id)
FROM revlog
WHERE id > cur.id
AND cid == cur.cid
)
) >= 4
"""
)
cnt = len(revlog_ids)
mw.col.db.execute(f"DELETE FROM revlog WHERE id IN {ids2str(revlog_ids)}")
col_set_modified()
tooltip(f"{cnt} review logs deleted.")
mw.reset()

0 comments on commit 7830911

Please sign in to comment.