diff options
author | Paco Guzman <pacoguzmanp@gmail.com> | 2016-06-02 15:46:58 +0200 |
---|---|---|
committer | Paco Guzman <pacoguzmanp@gmail.com> | 2016-06-17 19:04:36 +0200 |
commit | f6bfa46daae3a00ca6f74abb6e6eddc9eac96197 (patch) | |
tree | e80a1c3cde48387c034dbec51636b8d2c5277873 /app/services/todo_service.rb | |
parent | fcd9f90641d5ee59cc84d8388b7cc372370ac25a (diff) | |
download | gitlab-ce-f6bfa46daae3a00ca6f74abb6e6eddc9eac96197.tar.gz |
Cache todo counters (pending/done)18034-cache-todo-counter
- As todos are created/updated inside the TodoService
we repopulate the cache just there for both pending/done todos
- Todos as mark as done from the TodosController we update cache
there too
- All the added methods are kept in the User class for cohesion
Diffstat (limited to 'app/services/todo_service.rb')
-rw-r--r-- | app/services/todo_service.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index 5c0c1ba27bf..540bf54b920 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -1,6 +1,6 @@ # TodoService class # -# Used for creating todos after certain user actions +# Used for creating/updating todos after certain user actions # # Ex. # TodoService.new.new_issue(issue, current_user) @@ -137,6 +137,15 @@ class TodoService def mark_pending_todos_as_done(target, user) attributes = attributes_for_target(target) pending_todos(user, attributes).update_all(state: :done) + user.update_todos_count_cache + end + + # 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) + + todos.update_all(state: :done) + current_user.update_todos_count_cache end # When user marks an issue as todo @@ -151,6 +160,7 @@ class TodoService Array(users).map do |user| next if pending_todos(user, attributes).exists? Todo.create(attributes.merge(user_id: user.id)) + user.update_todos_count_cache end end |