Patch #26726
closed
Use pluck(:id) instead of collect(&:id)
Added by jwjw yy over 7 years ago.
Updated over 6 years ago.
Category:
Code cleanup/refactoring
Description
redmine/app/controllers/versions_controller.rb:37: project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
redmine/app/controllers/versions_controller.rb:37: project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
redmine/app/models/issue.rb:1383: moved_project_ids = project.self_and_descendants.reload.collect(&:id)
could change collect to pluck
- Description updated (diff)
- Category set to Code cleanup/refactoring
- Status changed from New to Needs feedback
And please describe why this change is effective.
Since pluck will only access the specific field but collect will retrieve every field of the object.
Toshi MARUYAMA wrote:
Please post by patch.
Please post by attachment patch file.
- Subject changed from collect(&:id) could be pluck(:id) to Use pluck(:id) instead of collect(&:id)
- Status changed from Needs feedback to New
- Target version set to 4.1.0
Index: app/controllers/versions_controller.rb
===================================================================
--- app/controllers/versions_controller.rb (revision 17452)
+++ app/controllers/versions_controller.rb (working copy)
@@ -34,7 +34,7 @@
@trackers = @project.trackers.sorted.to_a
retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
- project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
+ project_ids = @with_subprojects ? @project.self_and_descendants.pluck(:id) : [@project.id]
@versions = @project.shared_versions.preload(:custom_values)
@versions += @project.rolled_up_versions.visible.preload(:custom_values) if @with_subprojects
Index: app/models/issue.rb
===================================================================
--- app/models/issue.rb (revision 17452)
+++ app/models/issue.rb (working copy)
@@ -1383,7 +1383,7 @@
# Unassigns issues from versions that are no longer shared
# after +project+ was moved
def self.update_versions_from_hierarchy_change(project)
- moved_project_ids = project.self_and_descendants.reload.collect(&:id)
+ moved_project_ids = project.self_and_descendants.reload.pluck(:id)
# Update issues of the moved projects and issues assigned to a version of a moved project
Issue.update_versions(
["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)",
- Related to Patch #26711: Use pluck instead of collect/map added
- Status changed from New to Closed
- Target version deleted (
4.1.0)
Committed as r17454. Thank you.
Also available in: Atom
PDF