summaryrefslogtreecommitdiff
path: root/app/finders/todos_finder.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/todos_finder.rb')
-rw-r--r--app/finders/todos_finder.rb27
1 files changed, 19 insertions, 8 deletions
diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb
index 6e9c8ea6fde..74baf79e4f2 100644
--- a/app/finders/todos_finder.rb
+++ b/app/finders/todos_finder.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# TodosFinder
#
# Used to filter Todos by set of params
@@ -120,6 +122,7 @@ class TodosFinder
params[:sort] ? items.sort_by_attribute(params[:sort]) : items.order_id_desc
end
+ # rubocop: disable CodeReuse/ActiveRecord
def by_action(items)
if action?
items = items.where(action: to_action_id)
@@ -127,7 +130,9 @@ class TodosFinder
items
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def by_action_id(items)
if action_id?
items = items.where(action: action_id)
@@ -135,7 +140,9 @@ class TodosFinder
items
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def by_author(items)
if author?
items = items.where(author_id: author.try(:id))
@@ -143,7 +150,9 @@ class TodosFinder
items
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def by_project(items)
if project?
items = items.where(project: project)
@@ -151,19 +160,19 @@ class TodosFinder
items
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def by_group(items)
- if group?
- groups = group.self_and_descendants
- project_todos = items.where(project_id: Project.where(group: groups).select(:id))
- group_todos = items.where(group_id: groups.select(:id))
+ return items unless group?
- union = Gitlab::SQL::Union.new([project_todos, group_todos])
- items = Todo.from("(#{union.to_sql}) #{Todo.table_name}")
- end
+ groups = group.self_and_descendants
+ project_todos = items.where(project_id: Project.where(group: groups).select(:id))
+ group_todos = items.where(group_id: groups.select(:id))
- items
+ Todo.from_union([project_todos, group_todos])
end
+ # rubocop: enable CodeReuse/ActiveRecord
def by_state(items)
case params[:state].to_s
@@ -174,6 +183,7 @@ class TodosFinder
end
end
+ # rubocop: disable CodeReuse/ActiveRecord
def by_type(items)
if type?
items = items.where(target_type: type)
@@ -181,4 +191,5 @@ class TodosFinder
items
end
+ # rubocop: enable CodeReuse/ActiveRecord
end