about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2023-01-17 11:41:05 -0600
committerStarfall <us@starfall.systems>2023-01-17 11:41:05 -0600
commit1f9c919b8769f5b0a3424ef343e0049d33d656e3 (patch)
tree1853486629da4b3b76192fe8756e8d4f6d71adcb /app/lib
parent957c21273ff42d5b2b4a5e16b7869bbb09aeb865 (diff)
parent13227e1dafd308dfe1a3effc3379b766274809b3 (diff)
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/admin/system_check/elasticsearch_check.rb13
-rw-r--r--app/lib/feed_manager.rb3
-rw-r--r--app/lib/request.rb17
-rw-r--r--app/lib/status_reach_finder.rb2
-rw-r--r--app/lib/translation_service/libre_translate.rb2
-rw-r--r--app/lib/vacuum/feeds_vacuum.rb8
-rw-r--r--app/lib/vacuum/statuses_vacuum.rb5
7 files changed, 32 insertions, 18 deletions
diff --git a/app/lib/admin/system_check/elasticsearch_check.rb b/app/lib/admin/system_check/elasticsearch_check.rb
index 8aee18267..7f922978f 100644
--- a/app/lib/admin/system_check/elasticsearch_check.rb
+++ b/app/lib/admin/system_check/elasticsearch_check.rb
@@ -13,7 +13,14 @@ class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck
 
   def message
     if running_version.present?
-      Admin::SystemCheck::Message.new(:elasticsearch_version_check, I18n.t('admin.system_checks.elasticsearch_version_check.version_comparison', running_version: running_version, required_version: required_version))
+      Admin::SystemCheck::Message.new(
+        :elasticsearch_version_check,
+        I18n.t(
+          'admin.system_checks.elasticsearch_version_check.version_comparison',
+          running_version: running_version,
+          required_version: required_version
+        )
+      )
     else
       Admin::SystemCheck::Message.new(:elasticsearch_running_check)
     end
@@ -23,7 +30,8 @@ class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck
 
   def running_version
     @running_version ||= begin
-      Chewy.client.info['version']['number']
+      Chewy.client.info['version']['minimum_wire_compatibility_version'] ||
+        Chewy.client.info['version']['number']
     rescue Faraday::ConnectionFailed
       nil
     end
@@ -34,6 +42,7 @@ class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck
   end
 
   def compatible_version?
+    return false if running_version.nil?
     Gem::Version.new(running_version) >= Gem::Version.new(required_version)
   end
 end
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 9fe9ec346..14208e557 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -414,6 +414,7 @@ class FeedManager
     end
 
     return true if check_for_blocks.any? { |target_account_id| crutches[:blocking][target_account_id] || crutches[:muting][target_account_id] }
+    return true if crutches[:blocked_by][status.account_id]
 
     if status.reply? && !status.in_reply_to_account_id.nil?                                                                      # Filter out if it's a reply
       should_filter   = !crutches[:following][status.in_reply_to_account_id]                                                     # and I'm not following the person it's a reply to
@@ -606,7 +607,7 @@ class FeedManager
     crutches[:blocking]        = Block.where(account_id: receiver_id, target_account_id: check_for_blocks).pluck(:target_account_id).index_with(true)
     crutches[:muting]          = Mute.where(account_id: receiver_id, target_account_id: check_for_blocks).pluck(:target_account_id).index_with(true)
     crutches[:domain_blocking] = AccountDomainBlock.where(account_id: receiver_id, domain: statuses.flat_map { |s| [s.account.domain, s.reblog&.account&.domain] }.compact).pluck(:domain).index_with(true)
-    crutches[:blocked_by]      = Block.where(target_account_id: receiver_id, account_id: statuses.map { |s| s.reblog&.account_id }.compact).pluck(:account_id).index_with(true)
+    crutches[:blocked_by]      = Block.where(target_account_id: receiver_id, account_id: statuses.map { |s| [s.account_id, s.reblog&.account_id] }.flatten.compact).pluck(:account_id).index_with(true)
 
     crutches
   end
diff --git a/app/lib/request.rb b/app/lib/request.rb
index 96d934a8f..0508169dc 100644
--- a/app/lib/request.rb
+++ b/app/lib/request.rb
@@ -30,7 +30,8 @@ class Request
     @verb        = verb
     @url         = Addressable::URI.parse(url).normalize
     @http_client = options.delete(:http_client)
-    @options     = options.merge(socket_class: use_proxy? ? ProxySocket : Socket)
+    @allow_local = options.delete(:allow_local)
+    @options     = options.merge(socket_class: use_proxy? || @allow_local ? ProxySocket : Socket)
     @options     = @options.merge(proxy_url) if use_proxy?
     @headers     = {}
 
@@ -153,9 +154,7 @@ class Request
   end
 
   module ClientLimit
-    def body_with_limit(limit = 1.megabyte)
-      raise Mastodon::LengthValidationError if content_length.present? && content_length > limit
-
+    def truncated_body(limit = 1.megabyte)
       if charset.nil?
         encoding = Encoding::BINARY
       else
@@ -172,11 +171,19 @@ class Request
         contents << chunk
         chunk.clear
 
-        raise Mastodon::LengthValidationError if contents.bytesize > limit
+        break if contents.bytesize > limit
       end
 
       contents
     end
+
+    def body_with_limit(limit = 1.megabyte)
+      raise Mastodon::LengthValidationError if content_length.present? && content_length > limit
+
+      contents = truncated_body(limit)
+      raise Mastodon::LengthValidationError if contents.bytesize > limit
+      contents
+    end
   end
 
   if ::HTTP::Response.methods.include?(:body_with_limit) && !Rails.env.production?
diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb
index ccf1e9e3a..36fb0e80f 100644
--- a/app/lib/status_reach_finder.rb
+++ b/app/lib/status_reach_finder.rb
@@ -70,7 +70,7 @@ class StatusReachFinder
 
   def followers_inboxes
     if @status.in_reply_to_local_account? && distributable?
-      @status.account.followers.or(@status.thread.account.followers).inboxes
+      @status.account.followers.or(@status.thread.account.followers.not_domain_blocked_by_account(@status.account)).inboxes
     elsif @status.direct_visibility? || @status.limited_visibility?
       []
     else
diff --git a/app/lib/translation_service/libre_translate.rb b/app/lib/translation_service/libre_translate.rb
index 43576e306..4ebe21e45 100644
--- a/app/lib/translation_service/libre_translate.rb
+++ b/app/lib/translation_service/libre_translate.rb
@@ -27,7 +27,7 @@ class TranslationService::LibreTranslate < TranslationService
 
   def request(text, source_language, target_language)
     body = Oj.dump(q: text, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key)
-    req = Request.new(:post, "#{@base_url}/translate", body: body)
+    req = Request.new(:post, "#{@base_url}/translate", body: body, allow_local: true)
     req.add_headers('Content-Type': 'application/json')
     req
   end
diff --git a/app/lib/vacuum/feeds_vacuum.rb b/app/lib/vacuum/feeds_vacuum.rb
index 00b9fd646..b0246bc0d 100644
--- a/app/lib/vacuum/feeds_vacuum.rb
+++ b/app/lib/vacuum/feeds_vacuum.rb
@@ -10,14 +10,14 @@ class Vacuum::FeedsVacuum
   private
 
   def vacuum_inactive_home_feeds!
-    inactive_users.select(:id, :account_id).find_in_batches do |users|
-      feed_manager.clean_feeds!(:home, users.map(&:account_id))
+    inactive_users.select(:id, :account_id).in_batches do |users|
+      feed_manager.clean_feeds!(:home, users.pluck(:account_id))
     end
   end
 
   def vacuum_inactive_list_feeds!
-    inactive_users_lists.select(:id).find_in_batches do |lists|
-      feed_manager.clean_feeds!(:list, lists.map(&:id))
+    inactive_users_lists.select(:id).in_batches do |lists|
+      feed_manager.clean_feeds!(:list, lists.ids)
     end
   end
 
diff --git a/app/lib/vacuum/statuses_vacuum.rb b/app/lib/vacuum/statuses_vacuum.rb
index d1c4e7197..28c087b1c 100644
--- a/app/lib/vacuum/statuses_vacuum.rb
+++ b/app/lib/vacuum/statuses_vacuum.rb
@@ -19,10 +19,7 @@ class Vacuum::StatusesVacuum
       # as the search index, must be handled first.
       statuses.direct_visibility
               .includes(mentions: :account)
-              .find_each do |status|
-        # TODO: replace temporary solution - call of private model method
-        status.send(:unlink_from_conversations)
-      end
+              .find_each(&:unlink_from_conversations!)
       remove_from_search_index(statuses.ids) if Chewy.enabled?
 
       # Foreign keys take care of most associated records for us.