diff options
author | Robert Speicher <robert@gitlab.com> | 2017-04-28 21:41:37 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-04-28 21:41:37 +0300 |
commit | c3c465ace034d21764a11374902132eeed7a5f5b (patch) | |
tree | 863e7c4ac0dc086603b80c691406963c1f43061d /app/services | |
parent | 15eaca817140c315bf8ded5a5ace265020fe75f5 (diff) | |
parent | a204d14c672e08a825479511473ba3999ed08434 (diff) |
Merge branch 'tc-no-todo-service-select' into 'master'
Avoid plucking Todo ids in TodoService
Closes #30374
See merge request !10845
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/issuable_base_service.rb | 2 | ||||
-rw-r--r-- | app/services/todo_service.rb | 16 |
2 files changed, 11 insertions, 7 deletions
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index b071a398481..17cb71be5f6 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -260,7 +260,7 @@ class IssuableBaseService < BaseService todo_service.mark_todo(issuable, current_user) when 'done' todo = TodosFinder.new(current_user).execute.find_by(target: issuable) - todo_service.mark_todos_as_done([todo], current_user) if todo + todo_service.mark_todos_as_done_by_ids(todo, current_user) if todo end end diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index b6e88b0280f..a19283cccd3 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -170,20 +170,22 @@ class TodoService # When user marks some todos as done def mark_todos_as_done(todos, current_user) - update_todos_state_by_ids(todos.select(&:id), current_user, :done) + update_todos_state(todos, current_user, :done) end def mark_todos_as_done_by_ids(ids, current_user) - update_todos_state_by_ids(ids, current_user, :done) + todos = todos_by_ids(ids, current_user) + mark_todos_as_done(todos, current_user) end # When user marks some todos as pending def mark_todos_as_pending(todos, current_user) - update_todos_state_by_ids(todos.select(&:id), current_user, :pending) + update_todos_state(todos, current_user, :pending) end def mark_todos_as_pending_by_ids(ids, current_user) - update_todos_state_by_ids(ids, current_user, :pending) + todos = todos_by_ids(ids, current_user) + mark_todos_as_pending(todos, current_user) end # When user marks an issue as todo @@ -198,9 +200,11 @@ class TodoService private - def update_todos_state_by_ids(ids, current_user, state) - todos = current_user.todos.where(id: ids) + def todos_by_ids(ids, current_user) + current_user.todos.where(id: Array(ids)) + end + def update_todos_state(todos, current_user, state) # Only update those that are not really on that state todos = todos.where.not(state: state) todos_ids = todos.pluck(:id) |