Patch #26721

use find_by instead of detect

Added by jwjw yy 5 months ago. Updated 5 months ago.

Status:Needs feedbackStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Code cleanup/refactoring
Target version:-

Description

In project.rb

enable_module(name)
 enabled_modules.detect {|m| m.name == name}
end 

should be replaced by in order to only get the specified enabled_module instead of doing filtering after retrieving them all.

enabled_modules.find_by(name: name)

project.rb.diff Magnifier (472 Bytes) jwjw yy, 2017-08-19 05:01

project.rb.2.diff Magnifier (1.07 KB) jwjw yy, 2017-08-19 05:27

project.rb.3.diff Magnifier (2.32 KB) jwjw yy, 2017-08-19 05:43

History

#1 Updated by jwjw yy 5 months ago

same situation for copy_issues

#2 Updated by jwjw yy 5 months ago

#3 Updated by Toshi MARUYAMA 5 months ago

  • Tracker changed from Defect to Patch
  • Description updated (diff)
  • Category set to Code cleanup/refactoring
  • Target version set to 4.1.0

Please don't use "Defect" tracker for not defect.
Please use code highlighting in description. It is too hard to read.

#4 Updated by Pavel Rosick√Ĺ 5 months ago

enabled_modules and versions are usually preloaded, so detect is more effective then find_by that will always trigger a new database query

#5 Updated by Toshi MARUYAMA 5 months ago

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

Also available in: Atom PDF