summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-04-21 11:36:34 +0200
committerToon Claes <toon@gitlab.com>2017-04-27 09:57:09 +0200
commita204d14c672e08a825479511473ba3999ed08434 (patch)
tree05018866869b1119b38c71a668503e91797a733b /lib/api
parentd031665a634e5d6fef980e837d6b227097850178 (diff)
downloadgitlab-ce-a204d14c672e08a825479511473ba3999ed08434.tar.gz
Avoid plucking Todo ids and use sub-queries insteadtc-no-todo-service-select
TodoService should not call `.select(&:id)` on todos, because this is bad performance. So instead use sub-queries, which will result in a single SQL query to the database. https://docs.gitlab.com/ee/development/sql.html#plucking-ids
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/todos.rb4
-rw-r--r--lib/api/v3/todos.rb4
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
index d1f7e364029..10aa64947fe 100644
--- a/lib/api/todos.rb
+++ b/lib/api/todos.rb
@@ -59,10 +59,10 @@ module API
requires :id, type: Integer, desc: 'The ID of the todo being marked as done'
end
post ':id/mark_as_done' do
+ TodoService.new.mark_todos_as_done_by_ids(params[:id], current_user)
todo = current_user.todos.find(params[:id])
- TodoService.new.mark_todos_as_done([todo], current_user)
- present todo.reload, with: Entities::Todo, current_user: current_user
+ present todo, with: ::API::Entities::Todo, current_user: current_user
end
desc 'Mark all todos as done'
diff --git a/lib/api/v3/todos.rb b/lib/api/v3/todos.rb
index e3b311d61cd..3e2c61f6dbd 100644
--- a/lib/api/v3/todos.rb
+++ b/lib/api/v3/todos.rb
@@ -11,10 +11,10 @@ module API
requires :id, type: Integer, desc: 'The ID of the todo being marked as done'
end
delete ':id' do
+ TodoService.new.mark_todos_as_done_by_ids(params[:id], current_user)
todo = current_user.todos.find(params[:id])
- TodoService.new.mark_todos_as_done([todo], current_user)
- present todo.reload, with: ::API::Entities::Todo, current_user: current_user
+ present todo, with: ::API::Entities::Todo, current_user: current_user
end
desc 'Mark all todos as done'