mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
a46ab86adf
Configurable soft limit of 7,500, and above that, configurable ratio of 1.1 * followers, controlled by: - MAX_FOLLOWS_THRESHOLD - MAX_FOLLOWS_RATIO Fix #2311
45 lines
831 B
Ruby
45 lines
831 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'csv'
|
|
|
|
class ImportWorker
|
|
include Sidekiq::Worker
|
|
|
|
sidekiq_options queue: 'pull', retry: false
|
|
|
|
attr_reader :import
|
|
|
|
def perform(import_id)
|
|
@import = Import.find(import_id)
|
|
|
|
Import::RelationshipWorker.push_bulk(import_rows) do |row|
|
|
[@import.account_id, row.first, relationship_type]
|
|
end
|
|
|
|
@import.destroy
|
|
end
|
|
|
|
private
|
|
|
|
def import_contents
|
|
Paperclip.io_adapters.for(@import.data).read
|
|
end
|
|
|
|
def relationship_type
|
|
case @import.type
|
|
when 'following'
|
|
'follow'
|
|
when 'blocking'
|
|
'block'
|
|
when 'muting'
|
|
'mute'
|
|
end
|
|
end
|
|
|
|
def import_rows
|
|
rows = CSV.new(import_contents).reject(&:blank?)
|
|
rows = rows.take(FollowLimitValidator.limit_for_account(@import.account)) if @import.type == 'following'
|
|
rows
|
|
end
|
|
end
|