From 1e49d2eab44f2d1449796daaacaac5cac64f23d7 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 16 Jan 2024 19:14:50 +0100 Subject: [PATCH] Polish migration e.g. update comment, more suitable name for the method etc. --- ...20240116180000_fix_unread_comments_inconsistencies.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/db/migrate/20240116180000_fix_unread_comments_inconsistencies.rb b/db/migrate/20240116180000_fix_unread_comments_inconsistencies.rb index d124731bc..1969cfb4d 100644 --- a/db/migrate/20240116180000_fix_unread_comments_inconsistencies.rb +++ b/db/migrate/20240116180000_fix_unread_comments_inconsistencies.rb @@ -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 @@ -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|