diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-05-01 18:24:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-01 18:24:42 +0200 |
commit | a41b3d0457451abf750ecd2e5576e4d516d8ab95 (patch) | |
tree | 9e2238c87c72ef0bdca8159e4beb886553cd8755 /lib | |
parent | 252deefe3433d0cedafd973becd0d85b5182eb49 (diff) | |
parent | 26a51291c74e7f27bf5e97bec9cd415d7ed48246 (diff) |
Merge pull request #1760 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/cli_helper.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/rack_middleware.rb | 2 | ||||
-rw-r--r-- | lib/mastodon/search_cli.rb | 7 | ||||
-rw-r--r-- | lib/mastodon/sidekiq_middleware.rb | 2 | ||||
-rw-r--r-- | lib/tasks/emojis.rake | 14 |
5 files changed, 24 insertions, 13 deletions
diff --git a/lib/mastodon/cli_helper.rb b/lib/mastodon/cli_helper.rb index aaee1fa91..a78a28e27 100644 --- a/lib/mastodon/cli_helper.rb +++ b/lib/mastodon/cli_helper.rb @@ -19,15 +19,18 @@ module Mastodon ProgressBar.create(total: total, format: '%c/%u |%b%i| %e') 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) if options[:concurrency] < 1 say('Cannot run with this concurrency setting, must be at least 1', :red) exit(1) 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) pool = Concurrent::FixedThreadPool.new(options[:concurrency]) @@ -52,6 +55,9 @@ module Mastodon result = ActiveRecord::Base.connection_pool.with_connection do yield(item) + ensure + RedisConfiguration.pool.checkin if Thread.current[:redis] + Thread.current[:redis] = nil end aggregate.increment(result) if result.is_a?(Integer) diff --git a/lib/mastodon/rack_middleware.rb b/lib/mastodon/rack_middleware.rb index 619a2c36d..8aa7911fe 100644 --- a/lib/mastodon/rack_middleware.rb +++ b/lib/mastodon/rack_middleware.rb @@ -19,7 +19,7 @@ class Mastodon::RackMiddleware end def clean_up_redis_socket! - Thread.current[:redis]&.close + RedisConfiguration.pool.checkin if Thread.current[:redis] Thread.current[:redis] = nil end diff --git a/lib/mastodon/search_cli.rb b/lib/mastodon/search_cli.rb index 6ad9d7b6a..74f980ba1 100644 --- a/lib/mastodon/search_cli.rb +++ b/lib/mastodon/search_cli.rb @@ -59,9 +59,7 @@ module Mastodon index.specification.lock! end - db_config = ActiveRecord::Base.configurations[Rails.env].dup - db_config['pool'] = options[:concurrency] + 1 - ActiveRecord::Base.establish_connection(db_config) + reset_connection_pools! pool = Concurrent::FixedThreadPool.new(options[:concurrency]) added = Concurrent::AtomicFixnum.new(0) @@ -139,6 +137,9 @@ module Mastodon sleep 1 rescue => e progress.log pastel.red("Error importing #{index}: #{e}") + ensure + RedisConfiguration.pool.checkin if Thread.current[:redis] + Thread.current[:redis] = nil end end end diff --git a/lib/mastodon/sidekiq_middleware.rb b/lib/mastodon/sidekiq_middleware.rb index 7ec4097df..c75e8401f 100644 --- a/lib/mastodon/sidekiq_middleware.rb +++ b/lib/mastodon/sidekiq_middleware.rb @@ -26,7 +26,7 @@ class Mastodon::SidekiqMiddleware end def clean_up_redis_socket! - Thread.current[:redis]&.close + RedisConfiguration.pool.checkin if Thread.current[:redis] Thread.current[:redis] = nil end diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake index 8faa48a95..d9db79940 100644 --- a/lib/tasks/emojis.rake +++ b/lib/tasks/emojis.rake @@ -1,6 +1,6 @@ # frozen_string_literal: true -def gen_border(codepoint) +def gen_border(codepoint, color) input = Rails.root.join('public', 'emoji', "#{codepoint}.svg") dest = Rails.root.join('public', 'emoji', "#{codepoint}_border.svg") doc = File.open(input) { |f| Nokogiri::XML(f) } @@ -19,7 +19,7 @@ def gen_border(codepoint) border_elem.delete('fill') - border_elem['stroke'] = 'white' + border_elem['stroke'] = color border_elem['stroke-linejoin'] = 'round' border_elem['stroke-width'] = '4px' @@ -91,12 +91,16 @@ namespace :emojis do desc 'Generate emoji variants with white borders' task :generate_borders do src = Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json') - emojis = '🎱🐜⚫🖤⬛◼️◾◼️✒️▪️💣🎳📷📸♣️🕶️✴️🔌💂♀️📽️🍳🦍💂🔪🕳️🕹️🕋🖊️🖋️💂♂️🎤🎓🎥🎼♠️🎩🦃📼📹🎮🐃🏴🐞🕺📱📲🚲👽⚾🐔☁️💨🕊️👀🍥👻🐐❕❔⛸️🌩️🔊🔇📃🌧️🐏🍚🍙🐓🐑💀☠️🌨️🔉🔈💬💭🏐🏳️⚪⬜◽◻️▫️' + emojis_light = '👽⚾🐔☁️💨🕊️👀🍥👻🐐❕❔⛸️🌩️🔊🔇📃🌧️🐏🍚🍙🐓🐑💀☠️🌨️🔉🔈💬💭🏐🏳️⚪⬜◽◻️▫️' + emojis_dark = '🎱🐜⚫🖤⬛◼️◾◼️✒️▪️💣🎳📷📸♣️🕶️✴️🔌💂♀️📽️🍳🦍💂🔪🕳️🕹️🕋🖊️🖋️💂♂️🎤🎓🎥🎼♠️🎩🦃📼📹🎮🐃🏴🐞🕺📱📲🚲' map = Oj.load(File.read(src)) - emojis.each_grapheme_cluster do |emoji| - gen_border map[emoji] + emojis_light.each_grapheme_cluster do |emoji| + gen_border map[emoji], 'black' + end + emojis_dark.each_grapheme_cluster do |emoji| + gen_border map[emoji], 'white' end end end |