Skip to content

Eliminate N+1 queries in Dashboard::TodosController

Stan Hu requested to merge sh-optimize-todos-controller into master

This appears to bring down the number of SQL queries on GitLab.com for my Todos page from 673 to 103.

Before

I, [2019-06-24T06:32:03.075359 #5318]  INFO -- : Route total (265): 321.9ms
I, [2019-06-24T06:32:03.075447 #5318]  INFO -- : Project total (58): 110.6ms
I, [2019-06-24T06:32:03.075473 #5318]  INFO -- : User total (67): 87.0ms
I, [2019-06-24T06:32:03.075494 #5318]  INFO -- : Namespace total (57): 67.9ms
I, [2019-06-24T06:32:03.075526 #5318]  INFO -- : Note total (33): 59.5ms
I, [2019-06-24T06:32:03.075575 #5318]  INFO -- : Group total (4): 31.9ms
I, [2019-06-24T06:32:03.075605 #5318]  INFO -- : Timelog total (20): 20.6ms
I, [2019-06-24T06:32:03.075624 #5318]  INFO -- : LabelLink total (20): 20.6ms
I, [2019-06-24T06:32:03.075641 #5318]  INFO -- : MergeRequest total (16): 20.4ms
I, [2019-06-24T06:32:03.075658 #5318]  INFO -- : Label total (18): 19.7ms
I, [2019-06-24T06:32:03.075674 #5318]  INFO -- : GroupMember total (6): 17.0ms
I, [2019-06-24T06:32:03.075760 #5318]  INFO -- : Issue total (10): 13.4ms
I, [2019-06-24T06:32:03.075802 #5318]  INFO -- : MergeRequestAssignee total (14): 13.4ms
I, [2019-06-24T06:32:03.075824 #5318]  INFO -- : MergeRequestDiff total (12): 13.3ms
I, [2019-06-24T06:32:03.075842 #5318]  INFO -- : MergeRequestDiffCommit total (12): 13.2ms
I, [2019-06-24T06:32:03.075874 #5318]  INFO -- : Metrics total (12): 11.8ms
I, [2019-06-24T06:32:03.075903 #5318]  INFO -- : Upload total (9): 11.2ms
I, [2019-06-24T06:32:03.075925 #5318]  INFO -- : MergeRequestBlock total (12): 11.0ms
I, [2019-06-24T06:32:03.075943 #5318]  INFO -- : IssueAssignee total (9): 8.7ms
I, [2019-06-24T06:32:03.075961 #5318]  INFO -- : Milestone total (8): 7.9ms
I, [2019-06-24T06:32:03.075981 #5318]  INFO -- : ProjectMember total (3): 3.8ms
I, [2019-06-24T06:32:03.075999 #5318]  INFO -- : Todo total (1): 3.8ms
I, [2019-06-24T06:32:03.076028 #5318]  INFO -- : ProjectFeature total (3): 2.8ms
I, [2019-06-24T06:32:03.076139 #5318]  INFO -- : License total (1): 1.4ms
I, [2019-06-24T06:32:03.076173 #5318]  INFO -- : UserStatus total (1): 1.1ms
I, [2019-06-24T06:32:03.076197 #5318]  INFO -- : UserCallout total (1): 1.0ms
I, [2019-06-24T06:32:03.076215 #5318]  INFO -- : UserPreference total (1): 0.7ms

After

I, [2019-06-24T06:35:13.926281 #12276]  INFO -- : Route total (17): 98.4ms
I, [2019-06-24T06:35:13.926379 #12276]  INFO -- : Group total (4): 68.1ms
I, [2019-06-24T06:35:13.926397 #12276]  INFO -- : Project total (10): 47.7ms
I, [2019-06-24T06:35:13.926410 #12276]  INFO -- : Note total (3): 43.5ms
I, [2019-06-24T06:35:13.926422 #12276]  INFO -- : User total (17): 37.0ms
I, [2019-06-24T06:35:13.926436 #12276]  INFO -- : GroupMember total (6): 21.4ms
I, [2019-06-24T06:35:13.926448 #12276]  INFO -- : MergeRequest total (5): 15.2ms
I, [2019-06-24T06:35:13.926460 #12276]  INFO -- : Namespace total (9): 13.5ms
I, [2019-06-24T06:35:13.926471 #12276]  INFO -- : Issue total (3): 8.8ms
I, [2019-06-24T06:35:13.926482 #12276]  INFO -- : Todo total (1): 7.4ms
I, [2019-06-24T06:35:13.926493 #12276]  INFO -- : MergeRequestDiffCommit total (1): 6.3ms
I, [2019-06-24T06:35:13.926506 #12276]  INFO -- : Upload total (2): 5.2ms
I, [2019-06-24T06:35:13.926517 #12276]  INFO -- : Metrics total (1): 5.1ms
I, [2019-06-24T06:35:13.926528 #12276]  INFO -- : Label total (2): 4.9ms
I, [2019-06-24T06:35:13.926538 #12276]  INFO -- : LabelLink total (2): 4.7ms
I, [2019-06-24T06:35:13.926588 #12276]  INFO -- : MergeRequestAssignee total (3): 4.7ms
I, [2019-06-24T06:35:13.926605 #12276]  INFO -- : UserCallout total (1): 4.6ms
I, [2019-06-24T06:35:13.926622 #12276]  INFO -- : ProjectMember total (3): 4.5ms
I, [2019-06-24T06:35:13.926639 #12276]  INFO -- : ProjectFeature total (3): 3.7ms
I, [2019-06-24T06:35:13.926657 #12276]  INFO -- : MergeRequestDiff total (1): 3.5ms
I, [2019-06-24T06:35:13.926675 #12276]  INFO -- : Timelog total (2): 3.3ms
I, [2019-06-24T06:35:13.926692 #12276]  INFO -- : Milestone total (1): 3.0ms
I, [2019-06-24T06:35:13.926712 #12276]  INFO -- : IssueAssignee total (2): 2.9ms
I, [2019-06-24T06:35:13.926730 #12276]  INFO -- : MergeRequestBlock total (1): 1.9ms
I, [2019-06-24T06:35:13.926748 #12276]  INFO -- : UserPreference total (1): 1.8ms
I, [2019-06-24T06:35:13.926766 #12276]  INFO -- : UserStatus total (1): 1.6ms
I, [2019-06-24T06:35:13.926785 #12276]  INFO -- : License total (1): 1.3ms

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/43042

Edited by Stan Hu

Merge request reports