From b2822d901bf701fbda314e6302b51ce828ee53ef Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 21 Jan 2013 19:47:01 -0600 Subject: [PATCH] fix n+1 query for translations on items#index --- app/controllers/items_controller.rb | 2 +- app/models/item/search/query.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 519e096c..c352adac 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -23,7 +23,7 @@ class ItemsController < ApplicationController end end elsif params.has_key?(:ids) && params[:ids].is_a?(Array) - @items = Item.find(params[:ids]) + @items = Item.includes(:translations).find(params[:ids]) assign_closeted! respond_to do |format| format.json { render :json => @items } diff --git a/app/models/item/search/query.rb b/app/models/item/search/query.rb index 88f8bd80..37a73569 100644 --- a/app/models/item/search/query.rb +++ b/app/models/item/search/query.rb @@ -65,7 +65,9 @@ class Item end result = FlexSearch.item_search(final_flex_params) - result.loaded_collection + result.scoped_loaded_collection( + :scopes => {'Item' => Item.includes(:translations)} + ) end # Load the text query labels from I18n, so that when we see, say,