Skip to content

Commit

Permalink
Polish migration
Browse files Browse the repository at this point in the history
e.g. update comment, more suitable name for the method etc.
  • Loading branch information
Splines committed Jan 16, 2024
1 parent f1650c7 commit 1e49d2e
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def up

User.find_each do |user|
had_user_unread_comments = user.unread_comments # boolean
has_user_unread_comments = fix_unread_comments_flag(user)
has_user_unread_comments = user_unread_comments?(user)

has_flag_changed = had_user_unread_comments != has_user_unread_comments
has_flag_changed = (had_user_unread_comments != has_user_unread_comments)
user.update(unread_comments: has_user_unread_comments) if has_flag_changed
num_fixed_users += 1 if has_flag_changed
end
Expand All @@ -25,9 +25,8 @@ def up
Rails.logger.debug { "Fixed #{num_fixed_users} users (unread comments flag)" }
end

# Fixes the unread_comments flag for a given user.
# Returns whether the user has unread comments (after a possible change).
def fix_unread_comments_flag(user)
# Checks and returns whether the user has unread comments.
def user_unread_comments?(user)
# Check for unread comments -- directly via Reader
readers = Reader.where(user: user)
readers.each do |reader|
Expand Down

0 comments on commit 1e49d2e

Please sign in to comment.