Merge commit '32f0e619f0
' into kb_migration_development
This commit is contained in:
commit
7c118ed1d0
446 changed files with 6295 additions and 3456 deletions
|
@ -43,7 +43,7 @@ class ActivityTracker
|
|||
|
||||
case @type
|
||||
when :basic
|
||||
redis.mget(*keys).map(&:to_i).sum
|
||||
redis.mget(*keys).sum(&:to_i)
|
||||
when :unique
|
||||
redis.pfcount(*keys)
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
|
|||
def perform
|
||||
return reject_payload! if delete_arrived_first?(@json['id']) || !related_to_local_activity?
|
||||
|
||||
with_lock("announce:#{value_or_id(@object)}") do
|
||||
with_redis_lock("announce:#{value_or_id(@object)}") do
|
||||
original_status = status_from_object
|
||||
|
||||
return reject_payload! if original_status.nil? || !announceable?(original_status)
|
||||
|
|
|
@ -46,9 +46,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
|
||||
def create_status
|
||||
return reject_payload! if unsupported_object_type? || non_matching_uri_hosts?(@account.uri, object_uri) || tombstone_exists? || !related_to_local_activity?
|
||||
return reject_payload! if reply_to_local? && reject_reply_to_local?
|
||||
return reject_payload! if (reply_to_local? || reply_to_local_account?) && reject_reply_to_local?
|
||||
|
||||
with_lock("create:#{object_uri}") do
|
||||
with_redis_lock("create:#{object_uri}") do
|
||||
return if delete_arrived_first?(object_uri) || poll_vote?
|
||||
|
||||
@status = find_existing_status
|
||||
|
@ -137,7 +137,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
}
|
||||
end
|
||||
|
||||
def process_audience
|
||||
def reply_to_local_account?
|
||||
accounts_in_audience.any?(&:local?)
|
||||
end
|
||||
|
||||
def accounts_in_audience
|
||||
return @accounts_in_audience if @accounts_in_audience
|
||||
|
||||
# Unlike with tags, there is no point in resolving accounts we don't already
|
||||
# know here, because silent mentions would only be used for local access control anyway
|
||||
accounts_in_audience = (audience_to + audience_cc).uniq.filter_map do |audience|
|
||||
|
@ -151,6 +157,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
accounts_in_audience.uniq!
|
||||
end
|
||||
|
||||
@accounts_in_audience = accounts_in_audience
|
||||
end
|
||||
|
||||
def process_audience
|
||||
accounts_in_audience.each do |account|
|
||||
# This runs after tags are processed, and those translate into non-silent
|
||||
# mentions, which take precedence
|
||||
|
@ -322,7 +332,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
poll = replied_to_status.preloadable_poll
|
||||
already_voted = true
|
||||
|
||||
with_lock("vote:#{replied_to_status.poll_id}:#{@account.id}") do
|
||||
with_redis_lock("vote:#{replied_to_status.poll_id}:#{@account.id}") do
|
||||
already_voted = poll.votes.where(account: @account).exists?
|
||||
poll.votes.create!(account: @account, choice: poll.options.index(@object['name']), uri: object_uri)
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
private
|
||||
|
||||
def delete_person
|
||||
with_lock("delete_in_progress:#{@account.id}", autorelease: 2.hours, raise_on_failure: false) do
|
||||
with_redis_lock("delete_in_progress:#{@account.id}", autorelease: 2.hours, raise_on_failure: false) do
|
||||
DeleteAccountService.new.call(@account, reserve_username: false, skip_activitypub: true)
|
||||
end
|
||||
end
|
||||
|
@ -20,14 +20,14 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
def delete_note
|
||||
return if object_uri.nil?
|
||||
|
||||
with_lock("delete_status_in_progress:#{object_uri}", raise_on_failure: false) do
|
||||
with_redis_lock("delete_status_in_progress:#{object_uri}", raise_on_failure: false) do
|
||||
unless non_matching_uri_hosts?(@account.uri, object_uri)
|
||||
# This lock ensures a concurrent `ActivityPub::Activity::Create` either
|
||||
# does not create a status at all, or has finished saving it to the
|
||||
# database before we try to load it.
|
||||
# Without the lock, `delete_later!` could be called after `delete_arrived_first?`
|
||||
# and `Status.find` before `Status.create!`
|
||||
with_lock("create:#{object_uri}") { delete_later!(object_uri) }
|
||||
with_redis_lock("create:#{object_uri}") { delete_later!(object_uri) }
|
||||
|
||||
Tombstone.find_or_create_by(uri: object_uri, account: @account)
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module ActivityPub::CaseTransform
|
|||
when Symbol then camel_lower(value.to_s).to_sym
|
||||
when String
|
||||
camel_lower_cache[value] ||= if value.start_with?('_:')
|
||||
"_:#{value.gsub(/\A_:/, '').underscore.camelize(:lower)}"
|
||||
"_:#{value.delete_prefix('_:').underscore.camelize(:lower)}"
|
||||
else
|
||||
value.underscore.camelize(:lower)
|
||||
end
|
||||
|
|
|
@ -357,10 +357,10 @@ class FeedManager
|
|||
return true if crutches[:languages][status.account_id].present? && status.language.present? && !crutches[:languages][status.account_id].include?(status.language)
|
||||
|
||||
check_for_blocks = crutches[:active_mentions][status.id] || []
|
||||
check_for_blocks.concat([status.account_id])
|
||||
check_for_blocks.push(status.account_id)
|
||||
|
||||
if status.reblog?
|
||||
check_for_blocks.concat([status.reblog.account_id])
|
||||
check_for_blocks.push(status.reblog.account_id)
|
||||
check_for_blocks.concat(crutches[:active_mentions][status.reblog_of_id] || [])
|
||||
end
|
||||
|
||||
|
@ -396,7 +396,7 @@ class FeedManager
|
|||
# the notification has been checked for mute/block. Therefore, it's not
|
||||
# necessary to check the author of the toot for mute/block again
|
||||
check_for_blocks = status.active_mentions.pluck(:account_id)
|
||||
check_for_blocks.concat([status.in_reply_to_account]) if status.reply? && !status.in_reply_to_account_id.nil?
|
||||
check_for_blocks.push(status.in_reply_to_account) if status.reply? && !status.in_reply_to_account_id.nil?
|
||||
|
||||
should_filter = blocks_or_mutes?(receiver_id, check_for_blocks, :mentions) # Filter if it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked (or muted)
|
||||
should_filter ||= (status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists?) # of if the account is silenced and I'm not following them
|
||||
|
@ -533,10 +533,10 @@ class FeedManager
|
|||
|
||||
check_for_blocks = statuses.flat_map do |s|
|
||||
arr = crutches[:active_mentions][s.id] || []
|
||||
arr.concat([s.account_id])
|
||||
arr.push(s.account_id)
|
||||
|
||||
if s.reblog?
|
||||
arr.concat([s.reblog.account_id])
|
||||
arr.push(s.reblog.account_id)
|
||||
arr.concat(crutches[:active_mentions][s.reblog_of_id] || [])
|
||||
end
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ class Importer::AccountsIndexImporter < Importer::BaseImporter
|
|||
in_work_unit(tmp) do |accounts|
|
||||
bulk = Chewy::Index::Import::BulkBuilder.new(index, to_index: accounts).bulk_body
|
||||
|
||||
indexed = bulk.select { |entry| entry[:index] }.size
|
||||
deleted = bulk.select { |entry| entry[:delete] }.size
|
||||
indexed = bulk.count { |entry| entry[:index] }
|
||||
deleted = bulk.count { |entry| entry[:delete] }
|
||||
|
||||
Chewy::Index::Import::BulkRequest.new(index).perform(bulk)
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ class Importer::TagsIndexImporter < Importer::BaseImporter
|
|||
in_work_unit(tmp) do |tags|
|
||||
bulk = Chewy::Index::Import::BulkBuilder.new(index, to_index: tags).bulk_body
|
||||
|
||||
indexed = bulk.select { |entry| entry[:index] }.size
|
||||
deleted = bulk.select { |entry| entry[:delete] }.size
|
||||
indexed = bulk.count { |entry| entry[:index] }
|
||||
deleted = bulk.count { |entry| entry[:delete] }
|
||||
|
||||
Chewy::Index::Import::BulkRequest.new(index).perform(bulk)
|
||||
|
||||
|
|
|
@ -8,21 +8,51 @@ class PermalinkRedirector
|
|||
end
|
||||
|
||||
def redirect_path
|
||||
if path_segments[0].present? && path_segments[0].start_with?('@') && path_segments[1] =~ /\d/
|
||||
find_status_url_by_id(path_segments[1])
|
||||
elsif path_segments[0].present? && path_segments[0].start_with?('@')
|
||||
find_account_url_by_name(path_segments[0])
|
||||
elsif path_segments[0] == 'statuses' && path_segments[1] =~ /\d/
|
||||
find_status_url_by_id(path_segments[1])
|
||||
elsif path_segments[0] == 'accounts' && path_segments[1] =~ /\d/
|
||||
find_account_url_by_id(path_segments[1])
|
||||
if at_username_status_request? || statuses_status_request?
|
||||
find_status_url_by_id(second_segment)
|
||||
elsif at_username_request?
|
||||
find_account_url_by_name(first_segment)
|
||||
elsif accounts_request? && record_integer_id_request?
|
||||
find_account_url_by_id(second_segment)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def at_username_status_request?
|
||||
at_username_request? && record_integer_id_request?
|
||||
end
|
||||
|
||||
def statuses_status_request?
|
||||
statuses_request? && record_integer_id_request?
|
||||
end
|
||||
|
||||
def at_username_request?
|
||||
first_segment.present? && first_segment.start_with?('@')
|
||||
end
|
||||
|
||||
def statuses_request?
|
||||
first_segment == 'statuses'
|
||||
end
|
||||
|
||||
def accounts_request?
|
||||
first_segment == 'accounts'
|
||||
end
|
||||
|
||||
def record_integer_id_request?
|
||||
second_segment =~ /\d/
|
||||
end
|
||||
|
||||
def first_segment
|
||||
path_segments.first
|
||||
end
|
||||
|
||||
def second_segment
|
||||
path_segments.second
|
||||
end
|
||||
|
||||
def path_segments
|
||||
@path_segments ||= @path.gsub(/\A\//, '').split('/')
|
||||
@path_segments ||= @path.delete_prefix('/').split('/')
|
||||
end
|
||||
|
||||
def find_status_url_by_id(id)
|
||||
|
|
|
@ -14,7 +14,11 @@ class StatusReachFinder
|
|||
end
|
||||
|
||||
def inboxes_for_misskey
|
||||
(reached_account_inboxes_for_misskey + followers_inboxes_for_misskey).uniq
|
||||
if banned_domains_for_misskey.empty?
|
||||
[]
|
||||
else
|
||||
(reached_account_inboxes_for_misskey + followers_inboxes_for_misskey).uniq
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -121,26 +125,28 @@ class StatusReachFinder
|
|||
|
||||
domains = banned_domains_of_status(@status)
|
||||
domains += banned_domains_of_status(@status.reblog) if @status.reblog? && @status.reblog.local?
|
||||
@banned_domains = domains.uniq
|
||||
@banned_domains = domains.uniq + banned_domains_for_misskey
|
||||
end
|
||||
|
||||
def banned_domains_of_status(status)
|
||||
blocks = DomainBlock.where(domain: nil)
|
||||
unless status.account.user&.setting_send_without_domain_blocks
|
||||
if status.account.user&.setting_send_without_domain_blocks
|
||||
[]
|
||||
else
|
||||
blocks = DomainBlock.where(domain: nil)
|
||||
blocks = blocks.or(DomainBlock.where(reject_send_not_public_searchability: true)) if status.compute_searchability != 'public'
|
||||
blocks = blocks.or(DomainBlock.where(reject_send_public_unlisted: true)) if status.public_unlisted_visibility?
|
||||
blocks = blocks.or(DomainBlock.where(reject_send_dissubscribable: true)) if status.account.dissubscribable
|
||||
blocks = blocks.or(DomainBlock.where(reject_send_media: true)) if status.with_media?
|
||||
blocks = blocks.or(DomainBlock.where(reject_send_sensitive: true)) if (status.with_media? && status.sensitive) || status.spoiler_text?
|
||||
blocks.pluck(:domain).uniq
|
||||
end
|
||||
blocks = blocks.or(DomainBlock.where(detect_invalid_subscription: true)) if status.public_unlisted_visibility? && status.account.user&.setting_reject_public_unlisted_subscription
|
||||
blocks = blocks.or(DomainBlock.where(detect_invalid_subscription: true)) if status.unlisted_visibility? && status.account.user&.setting_reject_unlisted_subscription
|
||||
blocks.pluck(:domain).uniq
|
||||
end
|
||||
|
||||
def banned_domains_for_misskey
|
||||
return @banned_domains_for_misskey if @banned_domains_for_misskey
|
||||
|
||||
return @banned_domains_for_misskey = [] if (!@status.account.user&.reject_public_unlisted_subscription? && !@status.account.user&.reject_unlisted_subscription?) || (!@status.public_unlisted_visibility? && !@status.unlisted_visibility?)
|
||||
|
||||
domains = banned_domains_for_misskey_of_status(@status)
|
||||
domains += banned_domains_for_misskey_of_status(@status.reblog) if @status.reblog? && @status.reblog.local?
|
||||
@banned_domains_for_misskey = domains.uniq
|
||||
|
|
18
app/lib/vacuum/imports_vacuum.rb
Normal file
18
app/lib/vacuum/imports_vacuum.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Vacuum::ImportsVacuum
|
||||
def perform
|
||||
clean_unconfirmed_imports!
|
||||
clean_old_imports!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clean_unconfirmed_imports!
|
||||
BulkImport.where(state: :unconfirmed).where('created_at <= ?', 10.minutes.ago).reorder(nil).in_batches.delete_all
|
||||
end
|
||||
|
||||
def clean_old_imports!
|
||||
BulkImport.where('created_at <= ?', 1.week.ago).reorder(nil).in_batches.delete_all
|
||||
end
|
||||
end
|
|
@ -57,7 +57,7 @@ class WebfingerResource
|
|||
end
|
||||
|
||||
def resource_without_acct_string
|
||||
resource.gsub(/\Aacct:/, '')
|
||||
resource.delete_prefix('acct:')
|
||||
end
|
||||
|
||||
def local_username
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue