From bf41a2e7525cc952686623b508023c169dbdfe2d Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Mon, 20 Mar 2017 09:20:46 +0100 Subject: Todos performance: Include associations in Finder --- app/finders/todos_finder.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/finders/todos_finder.rb') diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index b7f091f334d..13d33a1c31b 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -24,6 +24,7 @@ class TodosFinder def execute items = current_user.todos + items = include_associations(items) items = by_action_id(items) items = by_action(items) items = by_author(items) @@ -38,6 +39,17 @@ class TodosFinder private + def include_associations(items) + return items unless params[:include_associations] + + items.includes( + [ + target: { project: [:route, namespace: :route] }, + author: { namespace: :route }, + ] + ) + end + def action_id? action_id.present? && Todo::ACTION_NAMES.has_key?(action_id.to_i) end -- cgit v1.2.3