diff options
Diffstat (limited to 'app/models/todo.rb')
-rw-r--r-- | app/models/todo.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/todo.rb b/app/models/todo.rb index 176d5e56fc0..c8138587d83 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -148,6 +148,24 @@ class Todo < ApplicationRecord .order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) .order('todos.created_at') end + + def pluck_user_id + pluck(:user_id) + end + + # Count todos grouped by user_id and state, using an UNION query + # so we can utilize the partial indexes for each state. + def count_grouped_by_user_id_and_state + grouped_count = select(:user_id, 'count(id) AS count').group(:user_id) + + done = grouped_count.where(state: :done).select("'done' AS state") + pending = grouped_count.where(state: :pending).select("'pending' AS state") + union = unscoped.from_union([done, pending], remove_duplicates: false) + + connection.select_all(union).each_with_object({}) do |row, counts| + counts[[row['user_id'], row['state']]] = row['count'] + end + end end def resource_parent |