mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-27 20:38:48 +01:00
parent
9a2a1f7419
commit
b1f54e68b8
1 changed files with 1 additions and 9 deletions
|
|
@ -225,15 +225,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