Project

General

Profile

Actions

Patch #26726

closed

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

Added by jwjw yy over 7 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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/mapClosedGo MAEDA

Actions
Actions #1

Updated by Toshi MARUYAMA over 7 years ago

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

Please post by patch.

Actions #2

Updated by Toshi MARUYAMA over 7 years ago

And please describe why this change is effective.

Actions #3

Updated by jwjw yy over 7 years ago

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

Actions #4

Updated by Toshi MARUYAMA about 7 years ago

Toshi MARUYAMA wrote:

Please post by patch.

Please post by attachment patch file.

Actions #5

Updated by Go MAEDA over 6 years 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 (?)",
Actions #6

Updated by Go MAEDA over 6 years ago

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

Updated by Go MAEDA over 6 years ago

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

Committed as r17454. Thank you.

Actions

Also available in: Atom PDF