Class: Todos::Destroy::DestroyedIssuableService
- Inherits:
-
Object
- Object
- Todos::Destroy::DestroyedIssuableService
- Defined in:
- app/services/todos/destroy/destroyed_issuable_service.rb
Constant Summary collapse
- BATCH_SIZE =
100- BOUND_TARGET_TYPES =
Since we are moving towards work items, in some instances we create todos with ‘target_type: WorkItem` in other instances we still create todos with `target_type: Issue` So when an issue/work item is deleted, we just make sure to delete todos for both target types
%w[Issue WorkItem].freeze
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(target_id, target_type) ⇒ DestroyedIssuableService
constructor
A new instance of DestroyedIssuableService.
Constructor Details
#initialize(target_id, target_type) ⇒ DestroyedIssuableService
Returns a new instance of DestroyedIssuableService.
13 14 15 16 |
# File 'app/services/todos/destroy/destroyed_issuable_service.rb', line 13 def initialize(target_id, target_type) @target_id = target_id @target_type = BOUND_TARGET_TYPES.include?(target_type) ? BOUND_TARGET_TYPES : target_type end |
Instance Method Details
#execute ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/todos/destroy/destroyed_issuable_service.rb', line 18 def execute relation = Todo.for_target(target_id).for_type(target_type).limit(BATCH_SIZE) loop do result = relation.delete_all_returning(:user_id) break if result.empty? user_ids = result.map { |row| row['user_id'] }.uniq invalidate_todos_cache_counts(user_ids) end end |