0
0
Fork 0

Merge remote-tracking branch 'upstream/main'

This commit is contained in:
オスカー、 2024-10-28 21:25:56 +09:00
commit 1e70b14213
No known key found for this signature in database
GPG key ID: 139D6573F92DA9F7
385 changed files with 5806 additions and 3603 deletions

View file

@ -65,6 +65,8 @@ class Account < ApplicationRecord
)
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
REFRESH_DEADLINE = 6.hours
STALE_THRESHOLD = 1.day
DEFAULT_FIELDS_SIZE = 4
INSTANCE_ACTOR_ID = -99
@ -229,13 +231,13 @@ class Account < ApplicationRecord
end
def possibly_stale?
last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
last_webfingered_at.nil? || last_webfingered_at <= STALE_THRESHOLD.ago
end
def schedule_refresh_if_stale!
return unless last_webfingered_at.present? && last_webfingered_at <= BACKGROUND_REFRESH_INTERVAL.ago
AccountRefreshWorker.perform_in(rand(6.hours.to_i), id)
AccountRefreshWorker.perform_in(rand(REFRESH_DEADLINE), id)
end
def refresh!

View file

@ -40,7 +40,9 @@ class DomainBlock < ApplicationRecord
if suspend?
[:suspend]
else
[severity.to_sym, reject_media? ? :reject_media : nil, reject_reports? ? :reject_reports : nil].reject { |policy| policy == :noop || policy.nil? }
[severity.to_sym, reject_media? ? :reject_media : nil, reject_reports? ? :reject_reports : nil]
.reject { |policy| policy == :noop }
.compact
end
end

View file

@ -18,5 +18,6 @@ class FollowRecommendation < ApplicationRecord
belongs_to :account_summary, foreign_key: :account_id, inverse_of: false
belongs_to :account
scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) }
scope :unsupressed, -> { where.not(FollowRecommendationSuppression.where(FollowRecommendationSuppression.arel_table[:account_id].eq(arel_table[:account_id])).select(1).arel.exists) }
scope :localized, ->(locale) { unsupressed.joins(:account_summary).merge(AccountSummary.localized(locale)) }
end

View file

@ -11,7 +11,7 @@ class FollowRecommendationFilter
attr_reader :params, :language
def initialize(params)
@language = params.delete('language') || I18n.locale
@language = usable_language(params.delete('language') || I18n.locale)
@params = params
end
@ -22,4 +22,15 @@ class FollowRecommendationFilter
Account.includes(:account_stat).joins(:follow_recommendation).merge(FollowRecommendation.localized(@language).order(rank: :desc))
end
end
private
def usable_language(locale)
return locale if Trends.available_locales.include?(locale)
locale = locale.to_s.split(/[_-]/).first
return locale if Trends.available_locales.include?(locale)
nil
end
end

View file

@ -36,9 +36,14 @@ class IpBlock < ApplicationRecord
class << self
def blocked?(remote_ip)
blocked_ips_map = Rails.cache.fetch(CACHE_KEY) { FastIpMap.new(IpBlock.where(severity: :no_access).pluck(:ip)) }
blocked_ips_map.include?(remote_ip)
end
private
def blocked_ips_map
Rails.cache.fetch(CACHE_KEY) { FastIpMap.new(severity_no_access.pluck(:ip)) }
end
end
private

View file

@ -19,6 +19,8 @@ class LinkFeed < PublicFeed
scope.merge!(discoverable)
scope.merge!(attached_to_preview_card)
scope.merge!(account_filters_scope) if account?
scope.merge!(language_scope) if account&.chosen_languages.present?
scope.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
end

View file

@ -62,6 +62,6 @@ class NotificationPolicy < ApplicationRecord
private
def pending_notification_requests
@pending_notification_requests ||= notification_requests.limit(MAX_MEANINGFUL_COUNT).pick(Arel.sql('count(*), coalesce(sum(notifications_count), 0)::bigint'))
@pending_notification_requests ||= notification_requests.without_suspended.limit(MAX_MEANINGFUL_COUNT).pick(Arel.sql('count(*), coalesce(sum(notifications_count), 0)::bigint'))
end
end

View file

@ -26,6 +26,8 @@ class NotificationRequest < ApplicationRecord
before_save :prepare_notifications_count
scope :without_suspended, -> { joins(:from_account).merge(Account.without_suspended) }
def self.preload_cache_collection(requests)
cached_statuses_by_id = yield(requests.filter_map(&:last_status)).index_by(&:id) # Call cache_collection in block

View file

@ -303,12 +303,34 @@ class Status < ApplicationRecord
status_stat&.favourites_count || 0
end
# Reblogs count received from an external instance
def untrusted_reblogs_count
status_stat&.untrusted_reblogs_count unless local?
end
# Favourites count received from an external instance
def untrusted_favourites_count
status_stat&.untrusted_favourites_count unless local?
end
def increment_count!(key)
update_status_stat!(key => public_send(key) + 1)
if key == :favourites_count && !untrusted_favourites_count.nil?
update_status_stat!(favourites_count: favourites_count + 1, untrusted_favourites_count: untrusted_favourites_count + 1)
elsif key == :reblogs_count && !untrusted_reblogs_count.nil?
update_status_stat!(reblogs_count: reblogs_count + 1, untrusted_reblogs_count: untrusted_reblogs_count + 1)
else
update_status_stat!(key => public_send(key) + 1)
end
end
def decrement_count!(key)
update_status_stat!(key => [public_send(key) - 1, 0].max)
if key == :favourites_count && !untrusted_favourites_count.nil?
update_status_stat!(favourites_count: [favourites_count - 1, 0].max, untrusted_favourites_count: [untrusted_favourites_count - 1, 0].max)
elsif key == :reblogs_count && !untrusted_reblogs_count.nil?
update_status_stat!(reblogs_count: [reblogs_count - 1, 0].max, untrusted_reblogs_count: [untrusted_reblogs_count - 1, 0].max)
else
update_status_stat!(key => [public_send(key) - 1, 0].max)
end
end
def trendable?

View file

@ -17,11 +17,17 @@ class StatusPin < ApplicationRecord
validates_with StatusPinValidator
after_destroy :invalidate_cleanup_info
after_destroy :invalidate_cleanup_info, if: %i(account_matches_status_account? account_local?)
delegate :local?, to: :account, prefix: true
private
def invalidate_cleanup_info
return unless status&.account_id == account_id && account.local?
account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unpin)
end
def account_matches_status_account?
status&.account_id == account_id
end
end

View file

@ -4,18 +4,24 @@
#
# Table name: status_stats
#
# id :bigint(8) not null, primary key
# status_id :bigint(8) not null
# replies_count :bigint(8) default(0), not null
# reblogs_count :bigint(8) default(0), not null
# favourites_count :bigint(8) default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint(8) not null, primary key
# status_id :bigint(8) not null
# replies_count :bigint(8) default(0), not null
# reblogs_count :bigint(8) default(0), not null
# favourites_count :bigint(8) default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# untrusted_favourites_count :bigint(8)
# untrusted_reblogs_count :bigint(8)
#
class StatusStat < ApplicationRecord
belongs_to :status, inverse_of: :status_stat
before_validation :clamp_untrusted_counts
MAX_UNTRUSTED_COUNT = 100_000_000
def replies_count
[attributes['replies_count'], 0].max
end
@ -27,4 +33,11 @@ class StatusStat < ApplicationRecord
def favourites_count
[attributes['favourites_count'], 0].max
end
private
def clamp_untrusted_counts
self.untrusted_favourites_count = untrusted_favourites_count.to_i.clamp(0, MAX_UNTRUSTED_COUNT) if untrusted_favourites_count.present?
self.untrusted_reblogs_count = untrusted_reblogs_count.to_i.clamp(0, MAX_UNTRUSTED_COUNT) if untrusted_reblogs_count.present?
end
end

View file

@ -29,6 +29,8 @@ class Web::PushSubscription < ApplicationRecord
delegate :locale, to: :associated_user
generates_token_for :unsubscribe, expires_in: Web::PushNotificationWorker::TTL
def pushable?(notification)
policy_allows_notification?(notification) && alert_enabled_for_notification_type?(notification)
end