forked from rDrama/rDrama
delete inactive holes
parent
bec3ddb2a9
commit
10f3d4035d
|
@ -191,6 +191,21 @@ def stats(site=None):
|
||||||
if u.deflector and u.deflector < time.time():
|
if u.deflector and u.deflector < time.time():
|
||||||
u.deflector = None
|
u.deflector = None
|
||||||
|
|
||||||
|
one_week_ago = time.time() - 604800
|
||||||
|
active_holes = [x[0] for x in g.db.query(Submission.sub).distinct().filter(Submission.sub != None, Submission.created_utc > one_week_ago).all()]
|
||||||
|
|
||||||
|
dead_holes = g.db.query(Sub).filter(Sub.name.notin_(active_holes)).all()
|
||||||
|
names = [x.name for x in dead_holes]
|
||||||
|
|
||||||
|
posts = g.db.query(Submission).filter(Submission.sub.in_(names)).all()
|
||||||
|
for post in posts:
|
||||||
|
post.sub = None
|
||||||
|
g.db.add(post)
|
||||||
|
|
||||||
|
to_delete = g.db.query(Mod).filter(Mod.sub.in_(names)).all() + g.db.query(Exile).filter(Exile.sub.in_(names)).all() + g.db.query(SubBlock).filter(SubBlock.sub.in_(names)).all() + dead_holes
|
||||||
|
for x in to_delete:
|
||||||
|
g.db.delete(x)
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
Loading…
Reference in New Issue