Merge commit '9c2d5b534f
' into upstream-20250314
This commit is contained in:
commit
6548462ecb
84 changed files with 1719 additions and 418 deletions
43
app/models/concerns/status/fetch_replies_concern.rb
Normal file
43
app/models/concerns/status/fetch_replies_concern.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Status::FetchRepliesConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
# enable/disable fetching all replies
|
||||
FETCH_REPLIES_ENABLED = ENV['FETCH_REPLIES_ENABLED'] == 'true'
|
||||
|
||||
# debounce fetching all replies to minimize DoS
|
||||
FETCH_REPLIES_COOLDOWN_MINUTES = (ENV['FETCH_REPLIES_COOLDOWN_MINUTES'] || 15).to_i.minutes
|
||||
FETCH_REPLIES_INITIAL_WAIT_MINUTES = (ENV['FETCH_REPLIES_INITIAL_WAIT_MINUTES'] || 5).to_i.minutes
|
||||
|
||||
included do
|
||||
scope :created_recently, -> { where(created_at: FETCH_REPLIES_INITIAL_WAIT_MINUTES.ago..) }
|
||||
scope :not_created_recently, -> { where(created_at: ..FETCH_REPLIES_INITIAL_WAIT_MINUTES.ago) }
|
||||
scope :fetched_recently, -> { where(fetched_replies_at: FETCH_REPLIES_COOLDOWN_MINUTES.ago..) }
|
||||
scope :not_fetched_recently, -> { where(fetched_replies_at: [nil, ..FETCH_REPLIES_COOLDOWN_MINUTES.ago]) }
|
||||
|
||||
scope :should_not_fetch_replies, -> { local.or(created_recently.or(fetched_recently)) }
|
||||
scope :should_fetch_replies, -> { remote.not_created_recently.not_fetched_recently }
|
||||
|
||||
# statuses for which we won't receive update or deletion actions,
|
||||
# and should update when fetching replies
|
||||
# Status from an account which either
|
||||
# a) has only remote followers
|
||||
# b) has local follows that were created after the last update time, or
|
||||
# c) has no known followers
|
||||
scope :unsubscribed, lambda {
|
||||
remote.merge(
|
||||
Status.left_outer_joins(account: :followers).where.not(followers_accounts: { domain: nil })
|
||||
.or(where.not('follows.created_at < statuses.updated_at'))
|
||||
.or(where(follows: { id: nil }))
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
def should_fetch_replies?
|
||||
# we aren't brand new, and we haven't fetched replies since the debounce window
|
||||
FETCH_REPLIES_ENABLED && !local? && created_at <= FETCH_REPLIES_INITIAL_WAIT_MINUTES.ago && (
|
||||
fetched_replies_at.nil? || fetched_replies_at <= FETCH_REPLIES_COOLDOWN_MINUTES.ago
|
||||
)
|
||||
end
|
||||
end
|
|
@ -31,6 +31,7 @@
|
|||
# markdown :boolean default(FALSE)
|
||||
# limited_scope :integer
|
||||
# quote_of_id :bigint(8)
|
||||
# fetched_replies_at :datetime
|
||||
#
|
||||
|
||||
require 'ostruct'
|
||||
|
@ -41,6 +42,7 @@ class Status < ApplicationRecord
|
|||
include Paginable
|
||||
include RateLimitable
|
||||
include Status::DomainBlockConcern
|
||||
include Status::FetchRepliesConcern
|
||||
include Status::SafeReblogInsert
|
||||
include Status::SearchConcern
|
||||
include Status::SnapshotConcern
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue