Merge remote-tracking branch 'parent/main' into kb_migration
This commit is contained in:
commit
fdf1d6df38
41 changed files with 752 additions and 569 deletions
|
@ -299,7 +299,7 @@ class FeedManager
|
|||
add_to_feed(:home, account.id, status, aggregate_reblogs: aggregate)
|
||||
end
|
||||
|
||||
account.following.includes(:account_stat).find_each do |target_account|
|
||||
account.following.includes(:account_stat).reorder(nil).find_each do |target_account|
|
||||
if redis.zcard(timeline_key) >= limit
|
||||
oldest_home_score = redis.zrange(timeline_key, 0, 0, with_scores: true).first.last.to_i
|
||||
last_status_score = Mastodon::Snowflake.id_at(target_account.last_status_at)
|
||||
|
|
|
@ -27,6 +27,6 @@ class Importer::PublicStatusesIndexImporter < Importer::BaseImporter
|
|||
end
|
||||
|
||||
def scope
|
||||
Status.indexable
|
||||
Status.indexable.reorder(nil)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class Importer::StatusesIndexImporter < Importer::BaseImporter
|
|||
# from a different scope to avoid indexing them multiple times, but that
|
||||
# could end up being a very large array
|
||||
|
||||
scope.find_in_batches(batch_size: @batch_size) do |tmp|
|
||||
scope.reorder(nil).find_in_batches(batch_size: @batch_size) do |tmp|
|
||||
in_work_unit(tmp.map(&:status_id)) do |status_ids|
|
||||
deleted = 0
|
||||
|
||||
|
|
|
@ -9,23 +9,90 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
before
|
||||
after
|
||||
during
|
||||
in
|
||||
).freeze
|
||||
|
||||
class Query
|
||||
attr_reader :must_not_clauses, :must_clauses, :filter_clauses
|
||||
def initialize(clauses, options = {})
|
||||
raise ArgumentError if options[:current_account].nil?
|
||||
|
||||
def initialize(clauses)
|
||||
grouped = clauses.compact.chunk(&:operator).to_h
|
||||
@must_not_clauses = grouped.fetch(:must_not, [])
|
||||
@must_clauses = grouped.fetch(:must, [])
|
||||
@filter_clauses = grouped.fetch(:filter, [])
|
||||
@clauses = clauses
|
||||
@options = options
|
||||
|
||||
flags_from_clauses!
|
||||
end
|
||||
|
||||
def apply(search)
|
||||
def request
|
||||
search = Chewy::Search::Request.new(*indexes).filter(default_filter)
|
||||
|
||||
must_clauses.each { |clause| search = search.query.must(clause.to_query) }
|
||||
must_not_clauses.each { |clause| search = search.query.must_not(clause.to_query) }
|
||||
filter_clauses.each { |clause| search = search.filter(**clause.to_query) }
|
||||
search.query.minimum_should_match(1)
|
||||
|
||||
search
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clauses_by_operator
|
||||
@clauses_by_operator ||= @clauses.compact.chunk(&:operator).to_h
|
||||
end
|
||||
|
||||
def flags_from_clauses!
|
||||
@flags = clauses_by_operator.fetch(:flag, []).to_h { |clause| [clause.prefix, clause.term] }
|
||||
end
|
||||
|
||||
def must_clauses
|
||||
clauses_by_operator.fetch(:must, [])
|
||||
end
|
||||
|
||||
def must_not_clauses
|
||||
clauses_by_operator.fetch(:must_not, [])
|
||||
end
|
||||
|
||||
def filter_clauses
|
||||
clauses_by_operator.fetch(:filter, [])
|
||||
end
|
||||
|
||||
def indexes
|
||||
case @flags['in']
|
||||
when 'library'
|
||||
[StatusesIndex]
|
||||
else
|
||||
[PublicStatusesIndex, StatusesIndex]
|
||||
end
|
||||
end
|
||||
|
||||
def default_filter
|
||||
{
|
||||
bool: {
|
||||
should: [
|
||||
{
|
||||
term: {
|
||||
_index: PublicStatusesIndex.index_name,
|
||||
},
|
||||
},
|
||||
{
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
term: {
|
||||
_index: StatusesIndex.index_name,
|
||||
},
|
||||
},
|
||||
{
|
||||
term: {
|
||||
searchable_by: @options[:current_account].id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
minimum_should_match: 1,
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -113,6 +180,9 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
@filter = :created_at
|
||||
@type = :range
|
||||
@term = { gte: term, lte: term, time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
|
||||
when 'in'
|
||||
@operator = :flag
|
||||
@term = term
|
||||
else
|
||||
raise "Unknown prefix: #{prefix}"
|
||||
end
|
||||
|
@ -187,6 +257,6 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
end
|
||||
|
||||
rule(query: sequence(:clauses)) do
|
||||
Query.new(clauses)
|
||||
Query.new(clauses, current_account: current_account)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue