Skip to content

Commit

Permalink
fix: delete invalid database rows on startup (jbsparrow#531)
Browse files Browse the repository at this point in the history
Previously downloaded media files will never be updated so it better to just delete them
  • Loading branch information
NTFSvolume authored Jan 29, 2025
1 parent 6157ce0 commit 99eb7d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cyberdrop_dl/managers/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ async def startup(self) -> None:
await self.history_table.startup()
await self.hash_table.startup()
await self.temp_referer_table.startup()
await self.run_fixes()

async def run_fixes(self):
if not self.manager.cache_manager.get("fixed_empty_download_filenames"):
await self.history_table.delete_invalid_rows()
self.manager.cache_manager.save("fixed_empty_download_filenames", True)

async def close(self) -> None:
"""Close the DBManager."""
Expand Down
6 changes: 6 additions & 0 deletions cyberdrop_dl/utils/database/tables/history_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ async def fix_chevereto_domains(self) -> None:
await cursor.execute(query)
await self.db_conn.commit()

async def delete_invalid_rows(self) -> None:
query = """DELETE FROM media WHERE download_filename = '' """
cursor = await self.db_conn.cursor()
await cursor.execute(query)
await self.db_conn.commit()

async def check_complete(self, domain: str, url: URL, referer: URL) -> bool:
"""Checks whether an individual file has completed given its domain and url path."""
if self.ignore_history:
Expand Down

0 comments on commit 99eb7d3

Please sign in to comment.