forked from MarseyWorld/MarseyWorld
add purged_utc
parent
6bfd7ffe0e
commit
82f6ed31f2
|
@ -14,6 +14,7 @@ class Media(Base):
|
|||
size = Column(Integer)
|
||||
posterurl = Column(String)
|
||||
referrer = Column(String)
|
||||
purged_utc = Column(Integer)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if "created_utc" not in kwargs:
|
||||
|
|
|
@ -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)]
|
||||
|
||||
|
||||
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),
|
||||
or_(
|
||||
MediaUsage.deleted_utc < one_month_ago,
|
||||
MediaUsage.removed_utc < one_month_ago,
|
||||
),
|
||||
Media.purged_utc == None,
|
||||
Media.user_id != 380983,
|
||||
).order_by(Media.size.desc())
|
||||
|
||||
total_saved = 0
|
||||
for filename, size in to_delete:
|
||||
total_saved += size
|
||||
print(filename, humanize.naturalsize(size, binary=True), flush=True)
|
||||
for filename, media in to_delete:
|
||||
total_saved += media.size
|
||||
print(filename, humanize.naturalsize(media.size, binary=True), flush=True)
|
||||
# finish backing up first before uncommenting
|
||||
# media.purged_utc = time.time()
|
||||
# g.db.add(media)
|
||||
# os.remove(filename)
|
||||
# gevent.spawn(rclone_delete, f'no:{filename}')
|
||||
|
||||
|
|
|
@ -1912,8 +1912,12 @@ def delete_media_post(v):
|
|||
remove_image_using_link(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):
|
||||
posterurl = g.db.query(Media.posterurl).filter_by(filename=path).one_or_none()
|
||||
posterurl = media.poster_url
|
||||
if posterurl:
|
||||
remove_image_using_link(posterurl[0])
|
||||
purge_files_in_cloudflare_cache(posterurl[0])
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
alter table media add column purged_utc int;
|
Loading…
Reference in New Issue