Patch #26726

Use pluck(:id) instead of collect(&:id)

Added by jwjw yy over 1 year ago. Updated 5 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Code cleanup/refactoring
Target version:-

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


Related issues

Related to Redmine - Patch #26711: Use pluck instead of collect/map Closed

History

#1 Updated by Toshi MARUYAMA over 1 year ago

  • Description updated (diff)
  • Category set to Code cleanup/refactoring
  • Status changed from New to Needs feedback

Please post by patch.

#2 Updated by Toshi MARUYAMA over 1 year ago

And please describe why this change is effective.

#3 Updated by jwjw yy over 1 year ago

Since pluck will only access the specific field but collect will retrieve every field of the object.

#4 Updated by Toshi MARUYAMA over 1 year ago

Toshi MARUYAMA wrote:

Please post by patch.

Please post by attachment patch file.

#5 Updated by Go MAEDA 5 months ago

  • 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 (?)",

#6 Updated by Go MAEDA 5 months ago

  • Related to Patch #26711: Use pluck instead of collect/map added

#7 Updated by Go MAEDA 5 months ago

  • Status changed from New to Closed
  • Target version deleted (4.1.0)

Committed as r17454. Thank you.

Also available in: Atom PDF