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/lib/api
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-04-21 12:36:34 +0300
committerToon Claes <toon@iotcl.com>2017-08-03 17:31:05 +0300
commita723cba57493ec3220596ca8543a8b1b1ec118fe (patch)
treefc1048fe60a21339cef711caf69aff59edf5a5fb /lib/api
parentc39daf937bd62eedcbe7e3b44f107bb7e87452e7 (diff)
Avoid plucking Todo ids and use sub-queries instead
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.rb6
-rw-r--r--lib/api/v3/todos.rb6
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
index d1f7e364029..55191169dd4 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
- todo = current_user.todos.find(params[:id])
- TodoService.new.mark_todos_as_done([todo], current_user)
+ TodoService.new.mark_todos_as_done_by_ids(params[:id], current_user)
+ todo = Todo.find(params[:id])
- present todo.reload, with: Entities::Todo, current_user: current_user
+ present todo, with: 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..2f2cf259987 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
- todo = current_user.todos.find(params[:id])
- TodoService.new.mark_todos_as_done([todo], current_user)
+ TodoService.new.mark_todos_as_done_by_ids(params[:id], current_user)
+ todo = Todo.find(params[:id])
- 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'