mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
remove content from communities according to retention setting #254
This commit is contained in:
parent
8d60f8f4cd
commit
2c362e32f4
2 changed files with 11 additions and 4 deletions
12
app/cli.py
12
app/cli.py
|
@ -23,7 +23,7 @@ from app.constants import NOTIF_COMMUNITY, NOTIF_POST, NOTIF_REPLY
|
||||||
from app.email import send_verification_email, send_email
|
from app.email import send_verification_email, send_email
|
||||||
from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain, ActivityPubLog, \
|
from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain, ActivityPubLog, \
|
||||||
utcnow, Site, Instance, File, Notification, Post, CommunityMember, NotificationSubscription, PostReply, Language, \
|
utcnow, Site, Instance, File, Notification, Post, CommunityMember, NotificationSubscription, PostReply, Language, \
|
||||||
Tag, InstanceRole
|
Tag, InstanceRole, Community
|
||||||
from app.utils import file_get_contents, retrieve_block_list, blocked_domains, retrieve_peertube_block_list, \
|
from app.utils import file_get_contents, retrieve_block_list, blocked_domains, retrieve_peertube_block_list, \
|
||||||
shorten_string, get_request, html_to_text, blocked_communities
|
shorten_string, get_request, html_to_text, blocked_communities
|
||||||
|
|
||||||
|
@ -171,6 +171,15 @@ def register(app):
|
||||||
@app.cli.command('daily-maintenance')
|
@app.cli.command('daily-maintenance')
|
||||||
def daily_maintenance():
|
def daily_maintenance():
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
# Remove old content from communities
|
||||||
|
communities = Community.query.filter(Community.content_retention > 0).all()
|
||||||
|
for community in communities:
|
||||||
|
cut_off = utcnow() - timedelta(days=community.content_retention)
|
||||||
|
db.session.execute(text('UPDATE "post" SET deleted = true WHERE posted_at < :cut_off AND community_id = :community_id'), {
|
||||||
|
'cut_off': cut_off,
|
||||||
|
'community_id': community.id
|
||||||
|
})
|
||||||
|
|
||||||
# Remove activity older than 3 days
|
# Remove activity older than 3 days
|
||||||
db.session.query(ActivityPubLog).filter(ActivityPubLog.created_at < utcnow() - timedelta(days=3)).delete()
|
db.session.query(ActivityPubLog).filter(ActivityPubLog.created_at < utcnow() - timedelta(days=3)).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -280,6 +289,7 @@ def register(app):
|
||||||
db.session.delete(post_reply)
|
db.session.delete(post_reply)
|
||||||
|
|
||||||
for post in Post.query.filter(Post.deleted == True, Post.posted_at < utcnow() - timedelta(days=7)).all():
|
for post in Post.query.filter(Post.deleted == True, Post.posted_at < utcnow() - timedelta(days=7)).all():
|
||||||
|
post.delete_dependencies()
|
||||||
db.session.delete(post)
|
db.session.delete(post)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -343,8 +343,6 @@ class Topic(db.Model):
|
||||||
return existing_notification is not None
|
return existing_notification is not None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Community(db.Model):
|
class Community(db.Model):
|
||||||
query_class = FullTextSearchQuery
|
query_class = FullTextSearchQuery
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -573,7 +571,6 @@ class Community(db.Model):
|
||||||
db.session.query(Report).filter(Report.suspect_community_id == self.id).delete()
|
db.session.query(Report).filter(Report.suspect_community_id == self.id).delete()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
user_role = db.Table('user_role',
|
user_role = db.Table('user_role',
|
||||||
db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
|
db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
|
||||||
db.Column('role_id', db.Integer, db.ForeignKey('role.id')),
|
db.Column('role_id', db.Integer, db.ForeignKey('role.id')),
|
||||||
|
|
Loading…
Add table
Reference in a new issue