DEV: Regression test for categories N+1 (#26204)

This commit is contained in:
Daniel Waterworth 2024-03-15 15:10:37 -05:00 committed by GitHub
parent 531e33b303
commit 1fbcc6936c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -314,6 +314,31 @@ RSpec.describe CategoriesController do
expect(category_response["subcategory_list"][0]["id"]).to eq(subcategory.id)
end
it "doesn't do more queries when more categories exist" do
SiteSetting.lazy_load_categories_groups = true
Theme.cache.clear
Fabricate(:category, parent_category: Fabricate(:category))
before_queries =
track_sql_queries do
get "/categories.json"
expect(response.status).to eq(200)
end
Fabricate(:category, parent_category: Fabricate(:category))
Theme.cache.clear
after_queries =
track_sql_queries do
get "/categories.json"
expect(response.status).to eq(200)
end
expect(after_queries.size).to eq(before_queries.size)
end
it "does not result in N+1 queries problem with multiple topics" do
category1 = Fabricate(:category)
category2 = Fabricate(:category)