Commit 1f225354 authored by Paco Guzman's avatar Paco Guzman

Use cache for todos counter calling TodoService

parent ec73abcd
...@@ -270,6 +270,7 @@ v 8.10.0 ...@@ -270,6 +270,7 @@ v 8.10.0
- Fix new snippet style bug (elliotec) - Fix new snippet style bug (elliotec)
- Instrument Rinku usage - Instrument Rinku usage
- Be explicit to define merge request discussion variables - Be explicit to define merge request discussion variables
- Use cache for todos counter calling TodoService
- Metrics for Rouge::Plugins::Redcarpet and Rouge::Formatters::HTMLGitlab - Metrics for Rouge::Plugins::Redcarpet and Rouge::Formatters::HTMLGitlab
- RailsCache metris now includes fetch_hit/fetch_miss and read_hit/read_miss info. - 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) - Allow [ci skip] to be in any case and allow [skip ci]. !4785 (simon_w)
......
...@@ -809,13 +809,13 @@ class User < ActiveRecord::Base ...@@ -809,13 +809,13 @@ class User < ActiveRecord::Base
def todos_done_count(force: false) def todos_done_count(force: false)
Rails.cache.fetch(['users', id, 'todos_done_count'], force: force) do Rails.cache.fetch(['users', id, 'todos_done_count'], force: force) do
todos.done.count TodosFinder.new(self, state: :done).execute.count
end end
end end
def todos_pending_count(force: false) def todos_pending_count(force: false)
Rails.cache.fetch(['users', id, 'todos_pending_count'], force: force) do Rails.cache.fetch(['users', id, 'todos_pending_count'], force: force) do
todos.pending.count TodosFinder.new(self, state: :pending).execute.count
end end
end end
......
...@@ -73,7 +73,7 @@ module API ...@@ -73,7 +73,7 @@ module API
# #
delete do delete do
todos = find_todos todos = find_todos
todos.each(&:done) TodoService.new.mark_todos_as_done(todos, current_user)
todos.length todos.length
end end
......
...@@ -117,6 +117,12 @@ describe API::Todos, api: true do ...@@ -117,6 +117,12 @@ describe API::Todos, api: true do
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(pending_1.reload).to be_done expect(pending_1.reload).to be_done
end 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
end end
...@@ -139,6 +145,12 @@ describe API::Todos, api: true do ...@@ -139,6 +145,12 @@ describe API::Todos, api: true do
expect(pending_2.reload).to be_done expect(pending_2.reload).to be_done
expect(pending_3.reload).to be_done expect(pending_3.reload).to be_done
end 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
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment