Preload max access level when loading group labels
What does this MR do and why?
This MR improves the group-level label search query by preloading the group max access levels for the current user. This prevents firing N+1 queries.
The optimization is behind a feature flag: preload_max_access_levels_for_labels_finder
I tested this with PG.ai, using the gitlab-org group:
RequestStore.begin!
current_user = User.find_by_username("ahegyi")
count = 0
ActiveSupport::Notifications.subscribe 'sql.active_record' do |*|
count += 1
end
puts LabelsFinder.new(
current_user,
group_id: 9970,
only_group_labels: false,
include_ancestor_groups: true,
include_descendant_groups: true
).execute.limit(100).pluck(:id)
puts "Query count: #{count}"
Query count (with and without the feature flag): 4 vs 237
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Adam Hegyi