Merge commit '6268188543
' into kb_migration
This commit is contained in:
commit
850c4dfb3c
133 changed files with 1644 additions and 947 deletions
|
@ -9,12 +9,11 @@ class AccountSearchService < BaseService
|
|||
MIN_QUERY_LENGTH = 5
|
||||
|
||||
def call(query, account = nil, options = {})
|
||||
@acct_hint = query&.start_with?('@')
|
||||
@query = query&.strip&.gsub(/\A@/, '')
|
||||
@limit = options[:limit].to_i
|
||||
@offset = options[:offset].to_i
|
||||
@options = options
|
||||
@account = account
|
||||
@query = query&.strip&.gsub(/\A@/, '')
|
||||
@limit = options[:limit].to_i
|
||||
@offset = options[:offset].to_i
|
||||
@options = options
|
||||
@account = account
|
||||
|
||||
search_service_results.compact.uniq
|
||||
end
|
||||
|
@ -72,8 +71,8 @@ class AccountSearchService < BaseService
|
|||
end
|
||||
|
||||
def from_elasticsearch
|
||||
must_clauses = [{ multi_match: { query: terms_for_query, fields: likely_acct? ? %w(acct.edge_ngram acct) : %w(acct.edge_ngram acct display_name.edge_ngram display_name), type: 'most_fields', operator: 'and' } }]
|
||||
should_clauses = []
|
||||
must_clauses = must_clause
|
||||
should_clauses = should_clause
|
||||
|
||||
if account
|
||||
return [] if options[:following] && following_ids.empty?
|
||||
|
@ -88,7 +87,7 @@ class AccountSearchService < BaseService
|
|||
query = { bool: { must: must_clauses, should: should_clauses } }
|
||||
functions = [reputation_score_function, followers_score_function, time_distance_function]
|
||||
|
||||
records = AccountsIndex.query(function_score: { query: query, functions: functions, boost_mode: 'multiply', score_mode: 'avg' })
|
||||
records = AccountsIndex.query(function_score: { query: query, functions: functions })
|
||||
.limit(limit_for_non_exact_results)
|
||||
.offset(offset)
|
||||
.objects
|
||||
|
@ -133,6 +132,36 @@ class AccountSearchService < BaseService
|
|||
}
|
||||
end
|
||||
|
||||
def must_clause
|
||||
fields = %w(username username.* display_name display_name.*)
|
||||
fields << 'text' << 'text.*' if options[:use_searchable_text]
|
||||
|
||||
[
|
||||
{
|
||||
multi_match: {
|
||||
query: terms_for_query,
|
||||
fields: fields,
|
||||
type: 'best_fields',
|
||||
operator: 'or',
|
||||
},
|
||||
},
|
||||
]
|
||||
end
|
||||
|
||||
def should_clause
|
||||
[
|
||||
{
|
||||
multi_match: {
|
||||
query: terms_for_query,
|
||||
fields: %w(username username.* display_name display_name.*),
|
||||
type: 'best_fields',
|
||||
operator: 'and',
|
||||
boost: 10,
|
||||
},
|
||||
},
|
||||
]
|
||||
end
|
||||
|
||||
def following_ids
|
||||
@following_ids ||= account.active_relationships.pluck(:target_account_id) + [account.id]
|
||||
end
|
||||
|
@ -182,8 +211,4 @@ class AccountSearchService < BaseService
|
|||
def username_complete?
|
||||
query.include?('@') && "@#{query}".match?(MENTION_ONLY_RE)
|
||||
end
|
||||
|
||||
def likely_acct?
|
||||
@acct_hint || username_complete?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,14 +10,6 @@ class ClearDomainMediaService < BaseService
|
|||
|
||||
private
|
||||
|
||||
def invalidate_association_caches!(status_ids)
|
||||
# Normally, associated models of a status are immutable (except for accounts)
|
||||
# so they are aggressively cached. After updating the media attachments to no
|
||||
# longer point to a local file, we need to clear the cache to make those
|
||||
# changes appear in the API and UI
|
||||
Rails.cache.delete_multi(status_ids.map { |id| "statuses/#{id}" })
|
||||
end
|
||||
|
||||
def clear_media!
|
||||
clear_account_images!
|
||||
clear_account_attachments!
|
||||
|
@ -25,31 +17,21 @@ class ClearDomainMediaService < BaseService
|
|||
end
|
||||
|
||||
def clear_account_images!
|
||||
blocked_domain_accounts.reorder(nil).find_each do |account|
|
||||
account.avatar.destroy if account.avatar&.exists?
|
||||
account.header.destroy if account.header&.exists?
|
||||
account.save
|
||||
blocked_domain_accounts.reorder(nil).find_in_batches do |accounts|
|
||||
AttachmentBatch.new(Account, accounts).clear
|
||||
end
|
||||
end
|
||||
|
||||
def clear_account_attachments!
|
||||
media_from_blocked_domain.reorder(nil).find_in_batches do |attachments|
|
||||
affected_status_ids = []
|
||||
|
||||
attachments.each do |attachment|
|
||||
affected_status_ids << attachment.status_id if attachment.status_id.present?
|
||||
|
||||
attachment.file.destroy if attachment.file&.exists?
|
||||
attachment.type = :unknown
|
||||
attachment.save
|
||||
end
|
||||
|
||||
invalidate_association_caches!(affected_status_ids) unless affected_status_ids.empty?
|
||||
AttachmentBatch.new(MediaAttachment, attachments).clear
|
||||
end
|
||||
end
|
||||
|
||||
def clear_emojos!
|
||||
emojis_from_blocked_domains.destroy_all
|
||||
emojis_from_blocked_domains.find_in_batches do |custom_emojis|
|
||||
AttachmentBatch.new(CustomEmoji, custom_emojis).delete
|
||||
end
|
||||
end
|
||||
|
||||
def blocked_domain
|
||||
|
|
|
@ -89,13 +89,28 @@ class ResolveURLService < BaseService
|
|||
def process_local_url
|
||||
recognized_params = Rails.application.routes.recognize_path(@url)
|
||||
|
||||
return unless recognized_params[:action] == 'show'
|
||||
case recognized_params[:controller]
|
||||
when 'statuses'
|
||||
return unless recognized_params[:action] == 'show'
|
||||
|
||||
if recognized_params[:controller] == 'statuses'
|
||||
status = Status.find_by(id: recognized_params[:id])
|
||||
check_local_status(status)
|
||||
elsif recognized_params[:controller] == 'accounts'
|
||||
when 'accounts'
|
||||
return unless recognized_params[:action] == 'show'
|
||||
|
||||
Account.find_local(recognized_params[:username])
|
||||
when 'home'
|
||||
return unless recognized_params[:action] == 'index' && recognized_params[:username_with_domain].present?
|
||||
|
||||
if recognized_params[:any]&.match?(/\A[0-9]+\Z/)
|
||||
status = Status.find_by(id: recognized_params[:any])
|
||||
check_local_status(status)
|
||||
elsif recognized_params[:any].blank?
|
||||
username, domain = recognized_params[:username_with_domain].gsub(/\A@/, '').split('@')
|
||||
return unless username.present? && domain.present?
|
||||
|
||||
Account.find_remote(username, domain)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ class SearchService < BaseService
|
|||
@query = query&.strip
|
||||
pull_query_commands
|
||||
|
||||
@account = account
|
||||
@options = options
|
||||
@limit = limit.to_i
|
||||
@offset = options[:type].blank? ? 0 : options[:offset].to_i
|
||||
@resolve = options[:resolve] || false
|
||||
@searchability = options[:searchability] || 'public'
|
||||
@account = account
|
||||
@options = options
|
||||
@limit = limit.to_i
|
||||
@offset = options[:type].blank? ? 0 : options[:offset].to_i
|
||||
@resolve = options[:resolve] || false
|
||||
@following = options[:following] || false
|
||||
|
||||
default_results.tap do |results|
|
||||
next if @query.blank? || @limit.zero?
|
||||
|
@ -36,7 +36,9 @@ class SearchService < BaseService
|
|||
@account,
|
||||
limit: @limit,
|
||||
resolve: @resolve,
|
||||
offset: @offset
|
||||
offset: @offset,
|
||||
use_searchable_text: true,
|
||||
following: @following
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue