Delete db entries too

This commit is contained in:
Sebastian Spaeth 2022-11-08 17:39:21 +01:00
parent 8410389d6a
commit be6da99c1c

View File

@ -76,8 +76,13 @@ class File:
for file in self.fullpath().glob('**/*'): for file in self.fullpath().glob('**/*'):
file.unlink() file.unlink()
self.fullpath().rmdir() self.fullpath().rmdir()
logging.debug(f"Deleted directory {self.fullpath()}") logging.debug(f"Deleted directory {self.fullpath()}")
#delete directory (self.fullpath()) with self.repo.conn.cursor() as cur:
cur.execute(f"DELETE from mediaapi_thumbnail WHERE media_id='%s';", self.media_id)
num_thumbnails = cur.rowcount
cur.execute(f"DELETE from mediaapi_media_repository WHERE media_id='%s';", self.media_id)
num_media = cur.rowcount
logging.debug(f"Deleted {num_media} + {num_thumbnails} db entries for media id {self.media_id}")
def exists(self): def exists(self):
"""returns True if the media file itself exists on the file system""" """returns True if the media file itself exists on the file system"""
@ -87,10 +92,10 @@ class File:
return (path / 'file').exists() return (path / 'file').exists()
def has_thumbnail(self): def has_thumbnail(self):
cur = self.repo.conn.cursor() with self.repo.conn.cursor() as cur:
# media_id | media_origin | content_type | file_size_bytes | creation_ts | upload_name | base64hash | user_id # media_id | media_origin | content_type | file_size_bytes | creation_ts | upload_name | base64hash | user_id
res = cur.execute(f"select COUNT(media_id) from mediaapi_thumbnail WHERE media_id='{self.media_id}';") cur.execute(f"select COUNT(media_id) from mediaapi_thumbnail WHERE media_id='{self.media_id}';")
row = cur.fetchone() row = cur.fetchone()
return(row[0]) return(row[0])
class MediaRepository: class MediaRepository: