mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Avoid StaleDataError exception during user.recalculate_attitude()
This commit is contained in:
parent
f36135d163
commit
915e8c779a
1 changed files with 14 additions and 13 deletions
|
@ -895,20 +895,21 @@ class User(UserMixin, db.Model):
|
|||
|
||||
def recalculate_attitude(self):
|
||||
upvotes = downvotes = 0
|
||||
last_50_votes = PostVote.query.filter(PostVote.user_id == self.id).order_by(-PostVote.id).limit(50)
|
||||
for vote in last_50_votes:
|
||||
if vote.effect > 0:
|
||||
upvotes += 1
|
||||
if vote.effect < 0:
|
||||
downvotes += 1
|
||||
with db.session.no_autoflush: # Avoid StaleDataError exception
|
||||
last_50_votes = PostVote.query.filter(PostVote.user_id == self.id).order_by(-PostVote.id).limit(50)
|
||||
for vote in last_50_votes:
|
||||
if vote.effect > 0:
|
||||
upvotes += 1
|
||||
if vote.effect < 0:
|
||||
downvotes += 1
|
||||
|
||||
comment_upvotes = comment_downvotes = 0
|
||||
last_50_votes = PostReplyVote.query.filter(PostReplyVote.user_id == self.id).order_by(-PostReplyVote.id).limit(50)
|
||||
for vote in last_50_votes:
|
||||
if vote.effect > 0:
|
||||
comment_upvotes += 1
|
||||
if vote.effect < 0:
|
||||
comment_downvotes += 1
|
||||
comment_upvotes = comment_downvotes = 0
|
||||
last_50_votes = PostReplyVote.query.filter(PostReplyVote.user_id == self.id).order_by(-PostReplyVote.id).limit(50)
|
||||
for vote in last_50_votes:
|
||||
if vote.effect > 0:
|
||||
comment_upvotes += 1
|
||||
if vote.effect < 0:
|
||||
comment_downvotes += 1
|
||||
|
||||
total_upvotes = upvotes + comment_upvotes
|
||||
total_downvotes = downvotes + comment_downvotes
|
||||
|
|
Loading…
Reference in a new issue