0
0
Fork 0

Change lists to reflect added and removed users retroactively (#32930)

This commit is contained in:
Eugen Rochko 2024-11-19 11:04:12 +01:00 committed by GitHub
parent f2976ec9a4
commit 2b5faa2ba3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 157 additions and 25 deletions

View file

@ -0,0 +1,33 @@
# frozen_string_literal: true
class AddAccountsToListService < BaseService
def call(list, accounts)
@list = list
@accounts = accounts
return if @accounts.empty?
update_list!
merge_into_list!
end
private
def update_list!
ApplicationRecord.transaction do
@accounts.each do |account|
@list.accounts << account
end
end
end
def merge_into_list!
MergeWorker.push_bulk(merge_account_ids) do |account_id|
[account_id, @list.id, 'list']
end
end
def merge_account_ids
ListAccount.where(list: @list, account: @accounts).where.not(follow_id: nil).pluck(:account_id)
end
end