Consider using a JOIN for system note metadata instead of a separate query when viewing merge requests
When viewing a merge request we eventually run the following query:
6.5ms SELECT "system_note_metadata".* FROM "system_note_metadata" WHERE "system_note_metadata"."note_id" IN (33491378, 33491607, 33491632, 33491644, 33567438, 33567439, 33567445, 33567446, 33567450, 33567451, 33567475, 33569202, 33569380, 33569644, 33569645, 33569646, 33569647, 33569743, 33569744, 33569745, 33569868, 33569869, 33570282, 33570284, 33570290, 33570291, 33570294, 33570295, 33570330, 33683055, 33689965, 33705535, 33795873, 34232660, 34233244, 34335009, 34335642, 34335671, 34336211, 34336252, 34336300, 34336368, 34336443, 34336530, 34337043, 34572672, 34572681, 34572686, 34572693, 34577442, 34578237, 34578393, 34578470, 34588613, 34588616, 34588618, 34588620, 34588622, 34588623, 34588624, 34590393, 34609534, 34609585, 34609626, 34609851, 34610680, 34611328, 34715114, 34723697, 34724227, 34724228, 34724235, 34724236, 34724563, 34731464, 34733324, 34733404, 34733631, 34811958, 34925626, 34954009, 35018560, 35022062, 35038987, 35153889, 35157480, 35160476, 35283312, 35283534, 35311484, 35311879, 35313181, 35313183, 35360895, 35496966, 35519803, 35596900, 35753507, 35757597, 35779673, 35854091, 35854198, 35855047, 35855316, 35863418, 35866826, 35868492, 35882163, 35968694, 36102057, 36166414, 36169240, 36187891, 36188084, 36188088, 36188109, 36189630, 36191778, 36192021, 36192206, 36192347, 36192391, 36192594, 36293234, 36293278, 36294224, 36294289, 36294524, 36294704, 36294727, 36295006, 36295153, 36295201, 36295573, 36295840, 36299038, 36299164, 36299507, 36299964, 36300565, 36300635, 36300669, 36300759, 36300878, 36301156, 36301249, 36301376, 36301429, 36301438, 36425149, 36425185, 36425229, 36425344, 36425628, 36425794, 36425847, 36425916, 36426068, 36428190, 36433041, 36433205, 36433395, 36433454, 36438462, 36438479, 36452791, 36455420, 36456507, 36456535, 36456546, 36458213, 36528385, 36546000, 36548154, 36562131, 36562376, 36562435, 36567849, 36567850, 36567851, 36567855, 36567865, 36568117, 36569415, 36569485, 36569672, 36569838, 36570735, 36571379, 36571810, 36572377, 36572773, 36573464, 36573600, 36573881, 36575014, 36575606, 36575634, 36576114, 36576247, 36577428, 36577496, 36580820, 36580822, 36580824, 36580829, 36580835, 36583500, 36584516, 36585879, 36586896, 36602362, 36638918, 36657071, 36657139, 36665274, 36665275, 36665278, 36665285, 36686598, 36687748, 36776667, 36788747, 36936520, 37037904, 37037907, 37051442, 37052460, 37052466, 37052471, 37052475, 37052690, 37058362, 37064468, 37066662, 37066704, 37066710, 37068487, 37068616, 37068716, 37068820, 37151138, 37151370, 37152485, 37152795, 37153751, 37155461, 37156910, 37256155, 37256728, 37257410, 37278788, 37279485, 37279547, 37280193, 37280483, 37280716, 37281352, 37281592, 37281594, 37283069, 37283138, 37283157, 37283181, 37283238, 37283295, 37283379, 37283477, 37283606, 37283688, 37283739, 37283862, 37283867, 37283927, 37283970, 37283972, 37283982, 37284135, 37284299, 37284322, 37287968, 37354378, 37354380, 37369729, 37369763, 37369767, 37371333, 37374414, 37374415, 37376661, 37389697, 37389820, 37390325, 37493426, 37523816, 37695230, 37723788, 37723789, 37724639, 37733253, 38060489, 38060653, 38358255, 38422903, 38889153, 40645189, 40702062, 40870006, 40874869, 40874870);
This gets all the system note metadata rows for all system notes. Instead of running a separate query we can just use a JOIN, assuming this table is a 1:1 relation with notes
. This in turn ensures this query's performance doesn't degrade as the number of system notes grows.