add purged_utc

master
Aevann 2024-10-24 19:11:06 +03:00
parent 6bfd7ffe0e
commit 82f6ed31f2
4 changed files with 14 additions and 5 deletions

View File

@ -14,6 +14,7 @@ class Media(Base):
size = Column(Integer) size = Column(Integer)
posterurl = Column(String) posterurl = Column(String)
referrer = Column(String) referrer = Column(String)
purged_utc = Column(Integer)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: if "created_utc" not in kwargs:

View File

@ -462,20 +462,23 @@ def _cleanup_videos():
clean = [x[0] for x in db.query(MediaUsage.filename).filter_by(deleted_utc=None, removed_utc=None)] clean = [x[0] for x in db.query(MediaUsage.filename).filter_by(deleted_utc=None, removed_utc=None)]
to_delete = db.query(MediaUsage.filename, Media.size).join(MediaUsage.media).filter( to_delete = db.query(MediaUsage.filename, Media).join(MediaUsage.media).filter(
MediaUsage.filename.notin_(clean), MediaUsage.filename.notin_(clean),
or_( or_(
MediaUsage.deleted_utc < one_month_ago, MediaUsage.deleted_utc < one_month_ago,
MediaUsage.removed_utc < one_month_ago, MediaUsage.removed_utc < one_month_ago,
), ),
Media.purged_utc == None,
Media.user_id != 380983, Media.user_id != 380983,
).order_by(Media.size.desc()) ).order_by(Media.size.desc())
total_saved = 0 total_saved = 0
for filename, size in to_delete: for filename, media in to_delete:
total_saved += size total_saved += media.size
print(filename, humanize.naturalsize(size, binary=True), flush=True) print(filename, humanize.naturalsize(media.size, binary=True), flush=True)
# finish backing up first before uncommenting # finish backing up first before uncommenting
# media.purged_utc = time.time()
# g.db.add(media)
# os.remove(filename) # os.remove(filename)
# gevent.spawn(rclone_delete, f'no:{filename}') # gevent.spawn(rclone_delete, f'no:{filename}')

View File

@ -1912,8 +1912,12 @@ def delete_media_post(v):
remove_image_using_link(extra_url) remove_image_using_link(extra_url)
purge_files_in_cloudflare_cache(extra_url) purge_files_in_cloudflare_cache(extra_url)
media = g.db.query(Media).filter_by(filename=path).one()
media.purged_utc = time.time()
g.db.add(media)
if url.startswith(SITE_FULL_VIDEOS): if url.startswith(SITE_FULL_VIDEOS):
posterurl = g.db.query(Media.posterurl).filter_by(filename=path).one_or_none() posterurl = media.poster_url
if posterurl: if posterurl:
remove_image_using_link(posterurl[0]) remove_image_using_link(posterurl[0])
purge_files_in_cloudflare_cache(posterurl[0]) purge_files_in_cloudflare_cache(posterurl[0])

View File

@ -0,0 +1 @@
alter table media add column purged_utc int;