From 9da87b68e92c6c3f253a338fae3cbd9a27e3ed98 Mon Sep 17 00:00:00 2001 From: Danilo Reyes Date: Sat, 28 Feb 2026 23:33:06 -0600 Subject: [PATCH] revision logic revisited --- src/download/admin.py | 4 ++++ src/download/admin_links.py | 13 +++++++++++++ src/download/db.py | 13 +++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/download/admin.py b/src/download/admin.py index 0222082..be17f77 100644 --- a/src/download/admin.py +++ b/src/download/admin.py @@ -14,6 +14,7 @@ from admin_links import cmd_remove from admin_links import cmd_rename from admin_links import cmd_unban from admin_links import cmd_validate_import +from admin_links import cmd_fix_revision from admin_users import cmd_user_rename from admin_users import cmd_users @@ -76,6 +77,9 @@ def build_parser() -> argparse.ArgumentParser: p_validate = sub.add_parser("validate-import") p_validate.set_defaults(func=cmd_validate_import) + p_fix_rev = sub.add_parser("fix-revision") + p_fix_rev.set_defaults(func=cmd_fix_revision) + p_user_rename = sub.add_parser("user-rename") p_user_rename.add_argument("user") p_user_rename.add_argument("site") diff --git a/src/download/admin_links.py b/src/download/admin_links.py index 4344054..f9fb326 100644 --- a/src/download/admin_links.py +++ b/src/download/admin_links.py @@ -205,6 +205,19 @@ def cmd_validate_import(_: argparse.Namespace) -> None: print(" OK") +def cmd_fix_revision(_: argparse.Namespace) -> None: + with db.connect() as conn: + conn.execute( + """ + UPDATE links + SET requires_revision = 0 + WHERE enabled = 1 OR banned_at IS NULL + """ + ) + conn.commit() + print("ok") + + def _fzf_select(lines: list[str], multi: bool) -> list[str]: if not lines: return [] diff --git a/src/download/db.py b/src/download/db.py index d4b62fa..764201b 100644 --- a/src/download/db.py +++ b/src/download/db.py @@ -170,6 +170,15 @@ def add_link( """, (user_name, url_original, url_norm, site), ) + if tombstone: + conn.execute( + """ + UPDATE links + SET requires_revision = 0 + WHERE id = ? + """, + (cur.lastrowid,), + ) add_history( conn, user_name=user_name, @@ -198,7 +207,7 @@ def set_enabled( conn.execute( """ UPDATE links - SET enabled = 1, disabled_at = NULL, updated_at = CURRENT_TIMESTAMP + SET enabled = 1, disabled_at = NULL, requires_revision = 0, updated_at = CURRENT_TIMESTAMP WHERE id = ? """, (row["id"],), @@ -252,7 +261,7 @@ def set_banned( conn.execute( """ UPDATE links - SET banned_at = NULL, banned_reason = NULL, updated_at = CURRENT_TIMESTAMP + SET banned_at = NULL, banned_reason = NULL, requires_revision = 0, updated_at = CURRENT_TIMESTAMP WHERE id = ? """, (row["id"],),