diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /app/models/todo.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
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 |