From 4189261cd03f95a256ec4c161d9395b38f104d2b Mon Sep 17 00:00:00 2001 From: Italo Matos Date: Sun, 4 Jan 2026 10:02:58 -0300 Subject: [PATCH] Refactor: Replace pluck(:id) with ids method Use the more idiomatic ActiveRecord ids method instead of pluck(:id) across controllers and models. The ids method is more readable and explicitly conveys the intent to retrieve primary key values. Changes: - BoardsController#edit: Use @board.users.ids - Board::Storage: Use cards.ids, Comment.where().ids, and ActionText::RichText.where().ids - User::Accessor: Use account.boards.all_access.ids This change improves code clarity while maintaining the same functionality. --- app/controllers/boards_controller.rb | 2 +- app/models/board/storage.rb | 7 +++---- app/models/user/accessor.rb | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 721e69b0d..5b8763b71 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -30,7 +30,7 @@ class BoardsController < ApplicationController end def edit - selected_user_ids = @board.users.pluck :id + selected_user_ids = @board.users.ids @selected_users, @unselected_users = \ @board.account.users.active.alphabetically.includes(:identity).partition { |user| selected_user_ids.include? user.id } end diff --git a/app/models/board/storage.rb b/app/models/board/storage.rb index 24028e714..126ba96ab 100644 --- a/app/models/board/storage.rb +++ b/app/models/board/storage.rb @@ -21,7 +21,7 @@ module Board::Storage end def card_ids - @card_ids ||= cards.pluck(:id) + @card_ids ||= cards.ids end def card_image_bytes @@ -36,7 +36,7 @@ module Board::Storage def comment_embed_bytes card_ids.each_slice(BATCH_SIZE).sum do |batch| - sum_embed_bytes_for "Comment", Comment.where(card_id: batch).pluck(:id) + sum_embed_bytes_for "Comment", Comment.where(card_id: batch).ids end end @@ -46,8 +46,7 @@ module Board::Storage def sum_embed_bytes_for(record_type, record_ids) rich_text_ids = ActionText::RichText \ - .where(record_type: record_type, record_id: record_ids) - .pluck(:id) + .where(record_type: record_type, record_id: record_ids).ids sum_blob_bytes_in_batches \ ActiveStorage::Attachment.where(record_type: "ActionText::RichText", name: "embeds"), diff --git a/app/models/user/accessor.rb b/app/models/user/accessor.rb index a9cc5e459..e8a24830f 100644 --- a/app/models/user/accessor.rb +++ b/app/models/user/accessor.rb @@ -13,6 +13,6 @@ module User::Accessor private def grant_access_to_boards - Access.insert_all account.boards.all_access.pluck(:id).collect { |board_id| { id: ActiveRecord::Type::Uuid.generate, board_id: board_id, user_id: id, account_id: account.id } } + Access.insert_all account.boards.all_access.ids.collect { |board_id| { id: ActiveRecord::Type::Uuid.generate, board_id: board_id, user_id: id, account_id: account.id } } end end