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.
This commit is contained in:
Italo Matos
2026-01-04 10:02:58 -03:00
parent 3fcf5a9d08
commit 4189261cd0
3 changed files with 5 additions and 6 deletions
+1 -1
View File
@@ -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
+3 -4
View File
@@ -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"),
+1 -1
View File
@@ -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