FIX: Query syntax error in UserBadge.update_featured_ranks! (#30979)

This commit fixes an SQL syntax error in
`UserBadge.update_featured_ranks!` when
the `user_ids` param is an empty array `[]`.

This was causing the `Jobs::BackfillBadge` job to raise the following
exceptions:

```
Job exception: ERROR:  syntax error at or near ")"
LINE 6:   AND user_id IN ()
```

This commit fixes the same error in
`UserState.update_distinct_badge_count` as well

Follow-up to 3e4eac0fed
This commit is contained in:
Alan Guo Xiang Tan
2025-01-24 14:06:39 +08:00
committed by GitHub
parent 084ed7a457
commit 62c6ee0de7
5 changed files with 38 additions and 13 deletions

View File

@@ -20,10 +20,14 @@ module Jobs
)
affected_user_ids = (revoked_user_ids | granted_user_ids).to_a
revoked_user_ids = revoked_user_ids.to_a
BadgeGranter.revoke_ungranted_titles!(revoked_user_ids.to_a)
UserBadge.ensure_consistency!(affected_user_ids)
UserStat.update_distinct_badge_count(affected_user_ids)
BadgeGranter.revoke_ungranted_titles!(revoked_user_ids) if revoked_user_ids.present?
if affected_user_ids.present?
UserBadge.ensure_consistency!(affected_user_ids)
UserStat.update_distinct_badge_count(affected_user_ids)
end
end
end
end