mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -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):
|
def recalculate_attitude(self):
|
||||||
upvotes = downvotes = 0
|
upvotes = downvotes = 0
|
||||||
last_50_votes = PostVote.query.filter(PostVote.user_id == self.id).order_by(-PostVote.id).limit(50)
|
with db.session.no_autoflush: # Avoid StaleDataError exception
|
||||||
for vote in last_50_votes:
|
last_50_votes = PostVote.query.filter(PostVote.user_id == self.id).order_by(-PostVote.id).limit(50)
|
||||||
if vote.effect > 0:
|
for vote in last_50_votes:
|
||||||
upvotes += 1
|
if vote.effect > 0:
|
||||||
if vote.effect < 0:
|
upvotes += 1
|
||||||
downvotes += 1
|
if vote.effect < 0:
|
||||||
|
downvotes += 1
|
||||||
|
|
||||||
comment_upvotes = comment_downvotes = 0
|
comment_upvotes = comment_downvotes = 0
|
||||||
last_50_votes = PostReplyVote.query.filter(PostReplyVote.user_id == self.id).order_by(-PostReplyVote.id).limit(50)
|
last_50_votes = PostReplyVote.query.filter(PostReplyVote.user_id == self.id).order_by(-PostReplyVote.id).limit(50)
|
||||||
for vote in last_50_votes:
|
for vote in last_50_votes:
|
||||||
if vote.effect > 0:
|
if vote.effect > 0:
|
||||||
comment_upvotes += 1
|
comment_upvotes += 1
|
||||||
if vote.effect < 0:
|
if vote.effect < 0:
|
||||||
comment_downvotes += 1
|
comment_downvotes += 1
|
||||||
|
|
||||||
total_upvotes = upvotes + comment_upvotes
|
total_upvotes = upvotes + comment_upvotes
|
||||||
total_downvotes = downvotes + comment_downvotes
|
total_downvotes = downvotes + comment_downvotes
|
||||||
|
|
Loading…
Add table
Reference in a new issue