mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-02 15:28:50 +01:00
parent
b03651ee97
commit
7e432887dd
1 changed files with 1 additions and 9 deletions
|
|
@ -234,15 +234,7 @@ class ContextsController < ApplicationController
|
|||
|
||||
def render_autocomplete
|
||||
lambda do
|
||||
# find contexts and the todos count. use a join to prevent all count(todos) of each context to be fetched
|
||||
context_and_todo_count = current_user.contexts.
|
||||
select('contexts.*, count(todos.id) as todos_count').
|
||||
joins('left outer join todos on context_id=contexts.id').
|
||||
group('context_id')
|
||||
|
||||
filled_contexts = context_and_todo_count.reject { |ctx| ctx.todos.size == 0 }
|
||||
empty_contexts = context_and_todo_count.find_all { |ctx| ctx.todos.size == 0 }
|
||||
render :text => for_autocomplete(filled_contexts + empty_contexts, params[:term])
|
||||
render :text => for_autocomplete(current_user.contexts, params[:term])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue