Skip to content

Draft: Performance increase in projects_helper

What does this MR do and why?

See #425166 (closed)

The goal is to fix the performance issue with the code behind project_templates_without_min_access feature flag and re-enable the FF.

Screenshot_2023-11-07_at_12.18.46

Refactoring results

[62] pry(main)> Project.all.count
=> 18

[62] pry(main)> control = ::ActiveRecord::QueryRecorder.new(skip_cached: false) do
[62] pry(main)*     Project.all.select { |project| can?(User.second, :download_code, project) }
[62] pry(main)* end
[62] pry(main)> control.count
=> 90

[63] pry(main)> compared = ::ActiveRecord::QueryRecorder.new(skip_cached: false) do
[63] pry(main)*   Ability.projects_downloadable_by_user(Project.all, User.second)
[63] pry(main)*  end
[62] pry(main)> compared.count
=> 58

[74] pry(main)> def recorder_duration(recoder)
  duration = 0
  recoder.data.each do |_, query_log|
    duration += query_log[:durations].sum
  end
  duration
end

[75] pry(main)> recorder_duration(compared)
=> 0.018966000000000004

[76] pry(main)> recorder_duration(control)
=> 0.027395999999999997

Related to #425166 (closed)

Edited by Patrick Cyiza

Merge request reports

Loading