remove obsolete flush_cache() calls

This commit is contained in:
rimu 2024-04-20 16:26:33 +12:00
parent c121ed6784
commit c8b81162f1
7 changed files with 2 additions and 37 deletions

View file

@ -1001,15 +1001,10 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
# Flush the caches of any major object that was created. To be sure.
if 'user' in vars() and user is not None:
user.flush_cache()
if user.instance_id and user.instance_id != 1:
user.instance.last_seen = utcnow()
# user.instance.ip_address = ip_address
user.instance.dormant = False
if 'community' in vars() and community is not None:
community.flush_cache()
if 'post' in vars() and post is not None:
post.flush_cache()
else:
activity_log.exception_message = 'Instance blocked'

View file

@ -1259,12 +1259,10 @@ def delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id
if deletor.is_admin() or community.is_moderator(deletor) or community.is_instance_admin(deletor) or to_delete.author.id == deletor.id:
if isinstance(to_delete, Post):
to_delete.delete_dependencies()
to_delete.flush_cache()
db.session.delete(to_delete)
community.post_count -= 1
db.session.commit()
elif isinstance(to_delete, PostReply):
to_delete.post.flush_cache()
to_delete.post.reply_count -= 1
if to_delete.has_replies():
to_delete.body = 'Deleted by author' if to_delete.author.id == deletor.id else 'Deleted by moderator'

View file

@ -569,7 +569,7 @@ def admin_user_edit(user_id):
flash(_("Permissions are cached for 50 seconds so new admin roles won't take effect immediately."))
db.session.commit()
user.flush_cache()
flash(_('Saved'))
return redirect(url_for('admin.admin_users', local_remote='local' if user.is_local() else 'remote'))
else:

View file

@ -385,7 +385,6 @@ def delete_post_from_community_task(post_id):
post = Post.query.get(post_id)
community = post.community
post.delete_dependencies()
post.flush_cache()
db.session.delete(post)
db.session.commit()
@ -447,7 +446,7 @@ def delete_post_reply_from_community_task(post_reply_id):
post_reply.delete_dependencies()
db.session.delete(post_reply)
db.session.commit()
post.flush_cache()
# federate delete
if not post.community.local_only:
delete_json = {

View file

@ -537,9 +537,6 @@ class Community(db.Model):
db.session.query(CommunityMember).filter(CommunityMember.community_id == self.id).delete()
db.session.query(Report).filter(Report.suspect_community_id == self.id).delete()
def flush_cache(self):
cache.delete('/c/' + self.name + '_False')
cache.delete('/c/' + self.name + '_True')
user_role = db.Table('user_role',
@ -839,9 +836,6 @@ class User(UserMixin, db.Model):
return
return User.query.get(id)
def flush_cache(self):
cache.delete('/u/' + self.user_name + '_False')
cache.delete('/u/' + self.user_name + '_True')
def delete_dependencies(self):
if self.cover_id:
@ -865,7 +859,6 @@ class User(UserMixin, db.Model):
posts = Post.query.filter_by(user_id=self.id).all()
for post in posts:
post.delete_dependencies()
post.flush_cache()
db.session.delete(post)
db.session.commit()
post_replies = PostReply.query.filter_by(user_id=self.id).all()
@ -989,10 +982,6 @@ class Post(db.Model):
return name
return False
def flush_cache(self):
cache.delete(f'/post/{self.id}_False')
cache.delete(f'/post/{self.id}_True')
class PostReply(db.Model):
query_class = FullTextSearchQuery
@ -1109,7 +1098,6 @@ class Domain(db.Model):
posts = Post.query.filter_by(domain_id=self.id).all()
for post in posts:
post.delete_dependencies()
post.flush_cache()
db.session.delete(post)
db.session.commit()

View file

@ -114,8 +114,6 @@ def show_post(post_id: int):
form.body.data = ''
flash('Your comment has been added.')
post.flush_cache()
# federation
reply_json = {
'type': 'Note',
@ -389,7 +387,6 @@ def post_vote(post_id: int, vote_direction):
db.session.commit()
current_user.recalculate_attitude()
db.session.commit()
post.flush_cache()
recently_upvoted = []
recently_downvoted = []
@ -502,8 +499,6 @@ def comment_vote(comment_id, vote_direction):
current_user.recalculate_attitude()
db.session.commit()
comment.post.flush_cache()
recently_upvoted = []
recently_downvoted = []
if vote_direction == 'upvote' and undo is None:
@ -620,8 +615,6 @@ def add_reply(post_id: int, comment_id: int):
form.body.data = ''
flash('Your comment has been added.')
post.flush_cache()
# federation
if not post.community.local_only:
reply_json = {
@ -793,7 +786,6 @@ def post_edit_discussion_post(post_id: int):
post.edited_at = utcnow()
db.session.commit()
post.flush_cache()
flash(_('Your changes have been saved.'), 'success')
# federate edit
@ -874,7 +866,6 @@ def post_edit_image_post(post_id: int):
db.session.commit()
post.flush_cache()
flash(_('Your changes have been saved.'), 'success')
# federate edit
@ -956,7 +947,6 @@ def post_edit_link_post(post_id: int):
db.session.commit()
post.flush_cache()
flash(_('Your changes have been saved.'), 'success')
# federate edit
@ -1038,7 +1028,6 @@ def post_edit_video_post(post_id: int):
db.session.commit()
post.flush_cache()
flash(_('Your changes have been saved.'), 'success')
# federate edit
@ -1159,7 +1148,6 @@ def post_delete(post_id: int):
if ocp.cross_posts is not None:
ocp.cross_posts.remove(post.id)
post.delete_dependencies()
post.flush_cache()
db.session.delete(post)
g.site.last_active = community.last_active = utcnow()
db.session.commit()
@ -1457,7 +1445,6 @@ def post_reply_edit(post_id: int, comment_id: int):
post.community.last_active = utcnow()
post_reply.edited_at = utcnow()
db.session.commit()
post.flush_cache()
flash(_('Your changes have been saved.'), 'success')
if post_reply.parent_id:
@ -1586,7 +1573,6 @@ def post_reply_delete(post_id: int, comment_id: int):
db.session.delete(post_reply)
g.site.last_active = community.last_active = utcnow()
db.session.commit()
post.flush_cache()
flash(_('Comment deleted.'))
# federate delete
if not post.community.local_only:

View file

@ -136,7 +136,6 @@ def edit_profile(actor):
file = save_banner_file(banner_file, 'users')
if file:
current_user.cover = file
current_user.flush_cache()
db.session.commit()