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