Remove block based post cleanup because of LIKE case insensivity issue.

This commit is contained in:
John Stephani 2026-02-26 01:03:24 -06:00
parent b7d80002a1
commit 8475353ac4
1 changed files with 23 additions and 20 deletions

View File

@ -13,26 +13,29 @@ def run():
delete = "DELETE FROM post WHERE created_utc < ? AND saved = ?"
binds = [max_created_utc, False]
cursor.execute(delete, binds)
print("Deleting posts from blocked subreddits")
select = "SELECT name FROM block WHERE name like '/r/%'"
binds = [row[0][3:] for row in cursor.execute(select).fetchall()]
bind_array = ",".join(["?"]*len(binds))
binds.append(False)
delete = f"DELETE FROM post WHERE subreddit IN ({bind_array}) AND saved = ?"
cursor.execute(delete, binds)
print("Deleting posts from blocked users")
select = "SELECT name FROM block WHERE name like '/u/%'"
binds = [row[0][3:] for row in cursor.execute(select).fetchall()]
bind_array = ",".join(["?"]*len(binds))
binds.append(False)
delete = f"DELETE FROM post WHERE author IN ({bind_array}) AND saved = ?"
cursor.execute(delete, binds)
print("Deleting posts with blocked words")
select = "SELECT name FROM block where name NOT LIKE '/u/%' AND name NOT LIKE '/r/%'"
binds = ["%"+row[0]+"%" for row in cursor.execute(select).fetchall()]
where_array = " OR ".join(["post LIKE ?"]*len(binds))
delete = f"DELETE FROM post WHERE {where_array}"
cursor.execute(delete, binds)
# LIKE is case insensitive by default, meaning a block on the word "ICE" would catch words like "nice"
# causing posts to get deleted and then redownloaded over and over again. Commenting out for now, might fix later.
# See 'PRAGMA case_sensitive_like = ON'
#print("Deleting posts from blocked subreddits")
#select = "SELECT name FROM block WHERE name like '/r/%'"
#binds = [row[0][3:] for row in cursor.execute(select).fetchall()]
#bind_array = ",".join(["?"]*len(binds))
#binds.append(False)
#delete = f"DELETE FROM post WHERE subreddit IN ({bind_array}) AND saved = ?"
#cursor.execute(delete, binds)
#print("Deleting posts from blocked users")
#select = "SELECT name FROM block WHERE name like '/u/%'"
#binds = [row[0][3:] for row in cursor.execute(select).fetchall()]
#bind_array = ",".join(["?"]*len(binds))
#binds.append(False)
#delete = f"DELETE FROM post WHERE author IN ({bind_array}) AND saved = ?"
#cursor.execute(delete, binds)
#print("Deleting posts with blocked words")
#select = "SELECT name FROM block where name NOT LIKE '/u/%' AND name NOT LIKE '/r/%'"
#binds = ["%"+row[0]+"%" for row in cursor.execute(select).fetchall()]
#where_array = " OR ".join(["post LIKE ?"]*len(binds))
#delete = f"DELETE FROM post WHERE {where_array}"
#cursor.execute(delete, binds)
print("Deleting old media db rows")
delete = "DELETE FROM media WHERE permalink NOT IN (SELECT permalink FROM post)"
cursor.execute(delete)