From 72826f87feebb8048cefb59aed16f1d9371c6271 Mon Sep 17 00:00:00 2001 From: krateng Date: Sat, 1 Apr 2023 16:11:20 +0200 Subject: [PATCH] Removing proxied image after they expire --- maloja/images.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/maloja/images.py b/maloja/images.py index 151c0cd..188df16 100644 --- a/maloja/images.py +++ b/maloja/images.py @@ -21,7 +21,7 @@ import sqlalchemy as sql -MAX_RESOLVE_THREADS = 10 +MAX_RESOLVE_THREADS = 5 # remove old db file (columns missing) @@ -126,10 +126,19 @@ def remove_image_from_cache(track_id=None,artist_id=None,album_id=None): with engine.begin() as conn: op = DB[table].delete().where( DB[table].c.id==entity_id, + ).returning( + DB[table].c.id, + DB[table].c.localproxyurl ) - result = conn.execute(op) + result = conn.execute(op).all() + + for row in result: + targetpath = data_dir['cache']('images',row.localproxyurl.split('/')[-1]) + try: + os.remove(targetpath) + except: + pass - # TODO delete proxy def dl_image(url): try: