Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-08-18 19:42:10 +0300
committerRuben Davila <rdavila84@gmail.com>2016-08-18 20:24:03 +0300
commitbb1f4f7b449710ed6ebb6fd4d535c96c84a7463e (patch)
treed22e2fc806bcfc6f4f61099e2001201d4082a69f /app
parentc069568a8394ce3cbe87df781e660a8d0faddb2f (diff)
Merge branch 'fix/simplify-todo-destroy-queries' into 'master'
Simplify SQL queries of marking a todo as done See merge request !5832
Diffstat (limited to 'app')
-rw-r--r--app/controllers/dashboard/todos_controller.rb6
-rw-r--r--app/services/todo_service.rb6
2 files changed, 6 insertions, 6 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb
index 1243bb96d4d..c8390af3b36 100644
--- a/app/controllers/dashboard/todos_controller.rb
+++ b/app/controllers/dashboard/todos_controller.rb
@@ -6,7 +6,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def destroy
- TodoService.new.mark_todos_as_done([todo], current_user)
+ TodoService.new.mark_todos_as_done_by_ids([params[:id]], current_user)
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
@@ -27,10 +27,6 @@ class Dashboard::TodosController < Dashboard::ApplicationController
private
- def todo
- @todo ||= find_todos.find(params[:id])
- end
-
def find_todos
@todos ||= TodosFinder.new(current_user, params).execute
end
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb
index eb833dd82ac..daf4339cb48 100644
--- a/app/services/todo_service.rb
+++ b/app/services/todo_service.rb
@@ -142,7 +142,11 @@ class TodoService
# When user marks some todos as done
def mark_todos_as_done(todos, current_user)
- todos = current_user.todos.where(id: todos.map(&:id)) unless todos.respond_to?(:update_all)
+ mark_todos_as_done_by_ids(todos.select(&:id), current_user)
+ end
+
+ def mark_todos_as_done_by_ids(ids, current_user)
+ todos = current_user.todos.where(id: ids)
marked_todos = todos.update_all(state: :done)
current_user.update_todos_count_cache