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