This commit is contained in:
Danilo Reyes
2026-02-28 23:59:08 -06:00
parent e73b4c8083
commit 76e3d72643

View File

@@ -222,19 +222,30 @@ def cmd_fix_x_media(_: argparse.Namespace) -> None:
with db.connect() as conn: with db.connect() as conn:
rows = conn.execute( rows = conn.execute(
""" """
SELECT id, url_original FROM links SELECT id, user_name, url_original FROM links
WHERE url_original LIKE '%x.com/%//media%' WHERE url_original LIKE '%x.com/%//media%'
""" """
).fetchall() ).fetchall()
for row in rows: for row in rows:
fixed = row["url_original"].replace("//media", "/media") fixed = row["url_original"].replace("//media", "/media")
norm = db.normalize_url(fixed)
conflict = conn.execute(
"""
SELECT id FROM links
WHERE user_name = ? AND url_normalized = ? AND id != ?
""",
(row["user_name"], norm, row["id"]),
).fetchone()
if conflict:
conn.execute("DELETE FROM links WHERE id = ?", (row["id"],))
continue
conn.execute( conn.execute(
""" """
UPDATE links UPDATE links
SET url_original = ?, url_normalized = ?, updated_at = CURRENT_TIMESTAMP SET url_original = ?, url_normalized = ?, updated_at = CURRENT_TIMESTAMP
WHERE id = ? WHERE id = ?
""", """,
(fixed, db.normalize_url(fixed), row["id"]), (fixed, norm, row["id"]),
) )
conn.commit() conn.commit()
print("ok") print("ok")