about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mastodon/cli_helper.rb12
-rw-r--r--lib/mastodon/rack_middleware.rb2
-rw-r--r--lib/mastodon/search_cli.rb7
-rw-r--r--lib/mastodon/settings_cli.rb14
-rw-r--r--lib/mastodon/sidekiq_middleware.rb2
-rw-r--r--lib/tasks/emojis.rake14
6 files changed, 38 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/settings_cli.rb b/lib/mastodon/settings_cli.rb
index 061650a80..488c655de 100644
--- a/lib/mastodon/settings_cli.rb
+++ b/lib/mastodon/settings_cli.rb
@@ -16,6 +16,20 @@ module Mastodon
       say('OK', :green)
     end
 
+    desc 'approved', 'Open approval-based registrations'
+    option :require_reason, type: :boolean, aliases: [:require_invite_text]
+    long_desc <<~LONG_DESC
+      Set registrations to require review from staff.
+
+      With --require-reason, require users to enter a reason when registering,
+      otherwise this field is optional.
+    LONG_DESC
+    def approved
+      Setting.registrations_mode = 'approved'
+      Setting.require_invite_text = options[:require_reason] unless options[:require_reason].nil?
+      say('OK', :green)
+    end
+
     desc 'close', 'Close registrations'
     def close
       Setting.registrations_mode = 'none'
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