From 2a265bbc1504528df63ae17d34e2b6ac1eb893fb Mon Sep 17 00:00:00 2001 From: John Ferlito Date: Sun, 12 May 2024 03:48:08 +1000 Subject: [PATCH] Fix N+1 query with preload --- app/oai/item_provider.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/oai/item_provider.rb b/app/oai/item_provider.rb index d41c4962..dd21325c 100644 --- a/app/oai/item_provider.rb +++ b/app/oai/item_provider.rb @@ -5,11 +5,10 @@ class ItemProvider < ApplicationProvider sample_id 'AA1-001' source_model OAI::Provider::ActiveRecordWrapper.new( - # FIXME: We should have collection to fix a N+1 query but it makes the query take 14 seconds ::Item.public_items.includes( :essences, :subject_languages, :content_languages, :countries, :access_condition, :collector, :data_types, :data_categories, item_agents: %i[user agent_role] - ), + ).preload(:collection), limit: 100 )