e7b1d201dd
read_project can be prevented by a very expensive condition, which we want to avoid, while still not writing manual SQL queries. read_project_for_iids is used by read_issue_iid and read_merge_request_iid to satisfy both of those constraints, and allow the declarative policy runner to use its normal caching strategy.
35 lines
1.1 KiB
Ruby
35 lines
1.1 KiB
Ruby
module ReferenceParserHelpers
|
|
def empty_html_link
|
|
Nokogiri::HTML.fragment('<a></a>').children[0]
|
|
end
|
|
|
|
shared_examples 'no N+1 queries' do
|
|
it 'avoids N+1 queries in #nodes_visible_to_user', :request_store do
|
|
record_queries = lambda do |links|
|
|
ActiveRecord::QueryRecorder.new do
|
|
described_class.new(project, user).nodes_visible_to_user(user, links)
|
|
end
|
|
end
|
|
|
|
control = record_queries.call(control_links)
|
|
actual = record_queries.call(actual_links)
|
|
|
|
expect(actual.count).to be <= control.count
|
|
expect(actual.cached_count).to be <= control.cached_count
|
|
end
|
|
|
|
it 'avoids N+1 queries in #records_for_nodes', :request_store do
|
|
record_queries = lambda do |links|
|
|
ActiveRecord::QueryRecorder.new do
|
|
described_class.new(project, user).records_for_nodes(links)
|
|
end
|
|
end
|
|
|
|
control = record_queries.call(control_links)
|
|
actual = record_queries.call(actual_links)
|
|
|
|
expect(actual.count).to be <= control.count
|
|
expect(actual.cached_count).to be <= control.cached_count
|
|
end
|
|
end
|
|
end
|