|
@ -19,15 +19,18 @@ module Mastodon |
|
|
ProgressBar.create(total: total, format: '%c/%u |%b%i| %e') |
|
|
ProgressBar.create(total: total, format: '%c/%u |%b%i| %e') |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def reset_connection_pools! |
|
|
|
|
|
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Rails.env].dup.tap { |config| config['pool'] = options[:concurrency] + 1 }) |
|
|
|
|
|
RedisConfiguration.establish_pool(options[:concurrency]) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
def parallelize_with_progress(scope) |
|
|
def parallelize_with_progress(scope) |
|
|
if options[:concurrency] < 1 |
|
|
if options[:concurrency] < 1 |
|
|
say('Cannot run with this concurrency setting, must be at least 1', :red) |
|
|
say('Cannot run with this concurrency setting, must be at least 1', :red) |
|
|
exit(1) |
|
|
exit(1) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
db_config = ActiveRecord::Base.configurations[Rails.env].dup |
|
|
|
|
|
db_config['pool'] = options[:concurrency] + 1 |
|
|
|
|
|
ActiveRecord::Base.establish_connection(db_config) |
|
|
|
|
|
|
|
|
reset_connection_pools! |
|
|
|
|
|
|
|
|
progress = create_progress_bar(scope.count) |
|
|
progress = create_progress_bar(scope.count) |
|
|
pool = Concurrent::FixedThreadPool.new(options[:concurrency]) |
|
|
pool = Concurrent::FixedThreadPool.new(options[:concurrency]) |
|
@ -52,6 +55,9 @@ module Mastodon |
|
|
|
|
|
|
|
|
result = ActiveRecord::Base.connection_pool.with_connection do |
|
|
result = ActiveRecord::Base.connection_pool.with_connection do |
|
|
yield(item) |
|
|
yield(item) |
|
|
|
|
|
ensure |
|
|
|
|
|
RedisConfiguration.pool.checkin if Thread.current[:redis] |
|
|
|
|
|
Thread.current[:redis] = nil |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
aggregate.increment(result) if result.is_a?(Integer) |
|
|
aggregate.increment(result) if result.is_a?(Integer) |
|
|