1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20241119

This commit is contained in:
KMY 2024-11-19 08:49:55 +09:00
commit 055045981f
221 changed files with 2006 additions and 1127 deletions

View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
class DomainResource
attr_reader :domain
RESOLVE_TIMEOUT = 5
def initialize(domain)
@domain = domain
end
def mx
Resolv::DNS.open do |dns|
dns.timeouts = RESOLVE_TIMEOUT
dns
.getresources(domain, Resolv::DNS::Resource::IN::MX)
.to_a
.map { |mx| mx.exchange.to_s }
.compact_blank
end
end
end

View file

@ -177,7 +177,7 @@ class FeedManager
timeline_key = key(:home, into_account.id)
timeline_status_ids = redis.zrange(timeline_key, 0, -1)
from_account.statuses.select('id, reblog_of_id').where(id: timeline_status_ids).reorder(nil).find_each do |status|
from_account.statuses.select(:id, :reblog_of_id).where(id: timeline_status_ids).reorder(nil).find_each do |status|
remove_from_feed(:home, into_account.id, status, aggregate_reblogs: into_account.user&.aggregates_reblogs?)
end
end
@ -190,7 +190,7 @@ class FeedManager
timeline_key = key(:list, list.id)
timeline_status_ids = redis.zrange(timeline_key, 0, -1)
from_account.statuses.select('id, reblog_of_id').where(id: timeline_status_ids).reorder(nil).find_each do |status|
from_account.statuses.select(:id, :reblog_of_id).where(id: timeline_status_ids).reorder(nil).find_each do |status|
remove_from_feed(:list, list.id, status, aggregate_reblogs: list.account.user&.aggregates_reblogs?)
end
end
@ -211,7 +211,7 @@ class FeedManager
.where.not(account: into_account.following)
.tagged_with_none(TagFollow.where(account: into_account).pluck(:tag_id))
scope.select('id, reblog_of_id').reorder(nil).find_each do |status|
scope.select(:id, :reblog_of_id).reorder(nil).find_each do |status|
remove_from_feed(:home, into_account.id, status, aggregate_reblogs: into_account.user&.aggregates_reblogs?)
end
end

View file

@ -80,7 +80,7 @@ class Importer::StatusesIndexImporter < Importer::BaseImporter
end
def local_votes_scope
Poll.joins(:votes).where(votes: { account: Account.local }).select('polls.id, polls.status_id')
Poll.joins(:votes).where(votes: { account: Account.local }).select(polls: [:id, :status_id])
end
def local_statuses_scope

View file

@ -282,6 +282,8 @@ class SearchQueryTransformer < Parslet::Transform
end
class PrefixClause
EPOCH_RE = /\A\d+\z/
attr_reader :operator, :prefix, :term
def initialize(prefix, operator, term, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
@ -311,15 +313,15 @@ class SearchQueryTransformer < Parslet::Transform
when 'before'
@filter = :created_at
@type = :range
@term = { lt: TermValidator.validate_date!(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
@term = { lt: date_from_term(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
when 'after'
@filter = :created_at
@type = :range
@term = { gt: TermValidator.validate_date!(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
@term = { gt: date_from_term(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
when 'during'
@filter = :created_at
@type = :range
@term = { gte: TermValidator.validate_date!(term), lte: TermValidator.validate_date!(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
@term = { gte: date_from_term(term), lte: date_from_term(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
when 'in'
@operator = :flag
@term = term
@ -409,16 +411,10 @@ class SearchQueryTransformer < Parslet::Transform
term
end
end
class TermValidator
STRICT_DATE_REGEX = /\A\d{4}-\d{2}-\d{2}\z/ # yyyy-MM-dd
EPOCH_MILLIS_REGEX = /\A\d{1,19}\z/
def self.validate_date!(value)
return value if value.match?(STRICT_DATE_REGEX) || value.match?(EPOCH_MILLIS_REGEX)
raise Mastodon::FilterValidationError, "Invalid date #{value}"
def date_from_term(term)
DateTime.iso8601(term) unless term.match?(EPOCH_RE) # This will raise Date::Error if the date is invalid
term
end
end