Duplicate noteable model loads causing significant performance regressions in loading merge requests
This looks like a significant performance regression in 9.2. We see that we load the same MergeRequest
for each note in a merge request:
D, [2017-05-28T05:52:03.200527 #51144] DEBUG -- : MergeRequest Load (1.8ms) SELECT "merge_requests".* FROM "merge_requests" WHERE "merge_requests"."deleted_at" IS NULL AND "merge_requests"."id" = 606001 ORDER BY "merge_requests"."id" DESC LIMIT 1 [["id", 606001]]
grep "MergeRequest Load" /tmp/e6dd6206-5dfb-4e12-adbd-40a4004eef98.txt | wc -l
108
This contributes to nearly a second of the load time for !2497
. The full trace:
D, [2017-05-28T05:51:19.338671 #51144] DEBUG -- : MergeRequest Load (1.7ms) SELECT "merge_requests".* FROM "merge_requests" WHERE "merge_requests"."deleted_at" IS NULL AND "merge_requests"."id" = 606001 ORDER BY "merge_requests"."id" DESC LIMIT 1 [["id", 606001]]
D, [2017-05-28T05:51:19.348096 #51144] DEBUG -- : ↳ lib/gitlab/database/load_balancing/connection_proxy.rb:59:in `block in read_using_load_balancer'
D, [2017-05-28T05:51:19.348348 #51144] DEBUG -- : ↳ lib/gitlab/database/load_balancing/load_balancer.rb:30:in `read'
D, [2017-05-28T05:51:19.348475 #51144] DEBUG -- : ↳ lib/gitlab/database/load_balancing/connection_proxy.rb:58:in `read_using_load_balancer'
D, [2017-05-28T05:51:19.348595 #51144] DEBUG -- : ↳ lib/gitlab/database/load_balancing/connection_proxy.rb:37:in `select_all'
D, [2017-05-28T05:51:19.348717 #51144] DEBUG -- : ↳ app/models/note.rb:202:in `noteable'
D, [2017-05-28T05:51:19.348835 #51144] DEBUG -- : ↳ app/models/note.rb:260:in `discussion_class'
D, [2017-05-28T05:51:19.348952 #51144] DEBUG -- : ↳ app/models/note.rb:269:in `discussion_id'
D, [2017-05-28T05:51:19.349069 #51144] DEBUG -- : ↳ app/models/discussion.rb:24:in `block in build_collection'
D, [2017-05-28T05:51:19.349185 #51144] DEBUG -- : ↳ app/models/discussion.rb:24:in `build_collection'
D, [2017-05-28T05:51:19.349302 #51144] DEBUG -- : ↳ app/models/note.rb:116:in `discussions'
D, [2017-05-28T05:51:19.349418 #51144] DEBUG -- : ↳ app/models/concerns/noteable.rb:36:in `discussions'
D, [2017-05-28T05:51:19.349534 #51144] DEBUG -- : ↳ app/controllers/projects/merge_requests_controller.rb:556:in `define_discussion_vars'
D, [2017-05-28T05:51:19.349651 #51144] DEBUG -- : ↳ app/controllers/projects/merge_requests_controller.rb:82:in `block (2 levels) in show'
D, [2017-05-28T05:51:19.349768 #51144] DEBUG -- : ↳ app/controllers/projects/merge_requests_controller.rb:80:in `show'