Skip to content

Commit

Permalink
Update task_runner.py
Browse files Browse the repository at this point in the history
try normalizing encrypted keys before duplicate removal
  • Loading branch information
LucifersCircle committed Dec 7, 2024
1 parent 049a730 commit c504535
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,36 @@ def remove_duplicates():
"""Remove duplicate keys from the database."""
try:
conn = sqlite3.connect(db_file)
# Find duplicate keys
duplicates_query = """
DELETE FROM keys
WHERE rowid NOT IN (
SELECT MIN(rowid)
FROM keys
GROUP BY encrypted_key
)
"""
cursor = conn.cursor()
cursor.execute(duplicates_query)
removed_count = cursor.rowcount # Get the number of rows affected

# Fetch all keys and normalize them
cursor.execute("SELECT rowid, encrypted_key FROM keys")
rows = cursor.fetchall()

# Use a set to track normalized keys and find duplicates
unique_keys = set()
duplicates = []
for rowid, encrypted_key in rows:
# Normalize key by stripping whitespace and converting to lowercase
normalized_key = encrypted_key.strip().lower() # Adjust normalization as needed
if normalized_key in unique_keys:
duplicates.append(rowid) # Track duplicate row IDs
else:
unique_keys.add(normalized_key)

# Remove duplicates by rowid
for rowid in duplicates:
cursor.execute("DELETE FROM keys WHERE rowid = ?", (rowid,))

conn.commit()
conn.close()
print(f"Removed {removed_count} duplicate keys from the database.", flush=True)

print(f"Removed {len(duplicates)} duplicate keys from the database.", flush=True)
except Exception as e:
print(f"Error removing duplicates: {e}", flush=True)



def fetch_keys():
"""Fetch and decrypt all keys from the database."""
try:
Expand Down

0 comments on commit c504535

Please sign in to comment.