From 805fd7c5d481459d7292303b16a85f0b62e19d06 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 22 Jun 2024 07:49:14 +0800 Subject: [PATCH] clean up bookmarks upon user or post deletion #26 --- app/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models.py b/app/models.py index 5a65324e..1f0b73bf 100644 --- a/app/models.py +++ b/app/models.py @@ -881,6 +881,8 @@ class User(UserMixin, db.Model): db.session.query(NotificationSubscription).filter(NotificationSubscription.user_id == self.id).delete() db.session.query(Notification).filter(Notification.user_id == self.id).delete() db.session.query(PollChoiceVote).filter(PollChoiceVote.user_id == self.id).delete() + db.session.query(PostBookmark).filter(PostBookmark.user_id == self.id).delete() + db.session.query(PostReplyBookmark).filter(PostReplyBookmark.user_id == self.id).delete() def purge_content(self, soft=True): files = File.query.join(Post).filter(Post.user_id == self.id).all() @@ -991,6 +993,7 @@ class Post(db.Model): return cls.query.filter_by(ap_id=ap_id).first() def delete_dependencies(self): + db.session.query(PostBookmark).filter(PostBookmark.post_id == self.id).delete() db.session.query(PollChoiceVote).filter(PollChoiceVote.post_id == self.id).delete() db.session.query(PollChoice).filter(PollChoice.post_id == self.id).delete() db.session.query(Poll).filter(Poll.post_id == self.id).delete() @@ -1147,6 +1150,7 @@ class PostReply(db.Model): child_reply.delete_dependencies() db.session.delete(child_reply) + db.session.query(PostReplyBookmark).filter(PostReplyBookmark.post_reply_id == self.id).delete() db.session.query(Report).filter(Report.suspect_post_reply_id == self.id).delete() db.session.execute(text('DELETE FROM post_reply_vote WHERE post_reply_id = :post_reply_id'), {'post_reply_id': self.id})