Patch #23328 » bench-23328-9-fixed.rb
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'benchmark/ips' |
4 |
|
5 |
project = Project.find(1) |
6 |
|
7 |
Benchmark.ips do |bench| |
8 |
bench.report('Redmine 5.1.0') do |
9 |
project.reload |
10 |
users = |
11 |
project.members.preload(:principal).select do |m| |
12 |
m.principal.present? && |
13 |
(m.mail_notification? || m.principal.mail_notification == 'all') |
14 |
end
|
15 |
users.collect {|m| m.principal} |
16 |
end
|
17 |
|
18 |
# The last version before `preload(:principal)` was added in r15518
|
19 |
bench.report('Redmine 3.2.6') do |
20 |
project.reload |
21 |
project.members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal} |
22 |
end
|
23 |
|
24 |
# bench.report('has_many_through') do
|
25 |
# project.reload
|
26 |
# project.users.where('members.mail_notification = ? OR users.mail_notification = ?', true, 'all').to_a
|
27 |
# end
|
28 |
|
29 |
bench.report('#23328#note-8') do |
30 |
project.reload |
31 |
subquery = |
32 |
project.members.select(:user_id) |
33 |
.where.associated(:principal) |
34 |
.where('members.mail_notification = ? OR users.mail_notification = ?', true, 'all') |
35 |
User.where(id: subquery).to_a |
36 |
end
|
37 |
|
38 |
bench.report('#23328#note-2') do |
39 |
project.reload |
40 |
project.members.eager_load(:principal).find_each() |
41 |
.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')} |
42 |
.collect {|m| m.principal} |
43 |
end
|
44 |
|
45 |
bench.compare! |
46 |
end
|