summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-07-08 18:42:47 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-07-08 18:48:05 +0200
commit140c917912ab29068d3609f353746f63cef9beb0 (patch)
tree0fd0b78504c08ab73fe239a71c316150dd48a946
parent140a706e96220ef1dab9ba220d86531ca5d46058 (diff)
downloadgitlab-ce-use-todos-finder-cached-data.tar.gz
Use cache for todos counter calling TodoServiceuse-todos-finder-cached-data
-rw-r--r--CHANGELOG1
-rw-r--r--app/helpers/todos_helper.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--lib/api/todos.rb2
-rw-r--r--spec/requests/api/todos_spec.rb12
5 files changed, 18 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 9f3bce52527..2bc5e25b5d3 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -43,6 +43,7 @@ v 8.10.0 (unreleased)
- Add API endpoint for a group issues !4520 (mahcsig)
- Add Bugzilla integration !4930 (iamtjg)
- Instrument Rinku usage
+ - Use cache for todos counter calling TodoService
- Metrics for Rouge::Plugins::Redcarpet and Rouge::Formatters::HTMLGitlab
- RailsCache metris now includes fetch_hit/fetch_miss and read_hit/read_miss info.
- Allow [ci skip] to be in any case and allow [skip ci]. !4785 (simon_w)
diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb
index a832a6c8df7..884ed9d2b6c 100644
--- a/app/helpers/todos_helper.rb
+++ b/app/helpers/todos_helper.rb
@@ -1,10 +1,10 @@
module TodosHelper
def todos_pending_count
- TodosFinder.new(current_user, state: :pending).execute.count
+ current_user.todos_pending_count
end
def todos_done_count
- TodosFinder.new(current_user, state: :done).execute.count
+ current_user.todos_done_count
end
def todo_action_name(todo)
diff --git a/app/models/user.rb b/app/models/user.rb
index 79c670cb35a..959cf96a821 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -829,13 +829,13 @@ class User < ActiveRecord::Base
def todos_done_count(force: false)
Rails.cache.fetch(['users', id, 'todos_done_count'], force: force) do
- todos.done.count
+ TodosFinder.new(self, state: :done).execute.count
end
end
def todos_pending_count(force: false)
Rails.cache.fetch(['users', id, 'todos_pending_count'], force: force) do
- todos.pending.count
+ TodosFinder.new(self, state: :pending).execute.count
end
end
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
index 2a6bfa98ca4..abdb21015b7 100644
--- a/lib/api/todos.rb
+++ b/lib/api/todos.rb
@@ -73,7 +73,7 @@ module API
#
delete do
todos = find_todos
- todos.each(&:done)
+ TodoService.new.mark_todos_as_done(todos, current_user)
present paginate(Kaminari.paginate_array(todos)), with: Entities::Todo, current_user: current_user
end
diff --git a/spec/requests/api/todos_spec.rb b/spec/requests/api/todos_spec.rb
index 92a4fa216cd..fc9d611712c 100644
--- a/spec/requests/api/todos_spec.rb
+++ b/spec/requests/api/todos_spec.rb
@@ -117,6 +117,12 @@ describe API::Todos, api: true do
expect(response.status).to eq(200)
expect(pending_1.reload).to be_done
end
+
+ it 'updates todos cache' do
+ expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original
+
+ delete api("/todos/#{pending_1.id}", john_doe)
+ end
end
end
@@ -140,6 +146,12 @@ describe API::Todos, api: true do
expect(pending_2.reload).to be_done
expect(pending_3.reload).to be_done
end
+
+ it 'updates todos cache' do
+ expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original
+
+ delete api("/todos", john_doe)
+ end
end
end