Skip to content

Commit

Permalink
add configurability via .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Oct 15, 2024
1 parent 437d95e commit e712283
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ MAX_POLL_OPTION_CHARS=100
# New registrations will automatically follow these accounts (separated by commas)
AUTOFOLLOW=

# -- Fetch all replies settings --
# When a user expands a post (DetailedStatus view), fetch all of its replies
# (default: true if unset, set explicitly to ``false`` to disable)
FETCH_REPLIES_ENABLED=true
# Period to wait between fetching replies (in minutes)
FETCH_REPLIES_DEBOUNCE=15
# Period to wait after a post is first created before fetching its replies (in minutes)
FETCH_REPLIES_CREATED_RECENTLY=5

# IP and session retention
# -----------------------
# Make sure to modify the scheduling of ip_cleanup_scheduler in config/sidekiq.yml
Expand Down
10 changes: 6 additions & 4 deletions app/models/concerns/status/fetch_replies_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
module Status::FetchRepliesConcern
extend ActiveSupport::Concern

# debounce fetching all replies to minimize DoS
FETCH_REPLIES_DEBOUNCE = 30.minutes
# enable/disable fetching all replies
FETCH_REPLIES_ENABLED = ENV.key?('FETCH_REPLIES_ENABLED') ? ENV['FETCH_REPLIES_ENABLED'] == 'true' : true

CREATED_RECENTLY_DEBOUNCE = 10.minutes
# debounce fetching all replies to minimize DoS
FETCH_REPLIES_DEBOUNCE = (ENV['FETCH_REPLIES_DEBOUNCE'] || 15).to_i.minutes
CREATED_RECENTLY_DEBOUNCE = (ENV['FETCH_REPLIES_CREATED_RECENTLY'] || 5).to_i.minutes

included do
scope :created_recently, -> { where(created_at: CREATED_RECENTLY_DEBOUNCE.ago..) }
Expand All @@ -20,7 +22,7 @@ module Status::FetchRepliesConcern

def should_fetch_replies?
# we aren't brand new, and we haven't fetched replies since the debounce window
!local? && created_at <= CREATED_RECENTLY_DEBOUNCE.ago && (
FETCH_REPLIES_ENABLED && !local? && created_at <= CREATED_RECENTLY_DEBOUNCE.ago && (
fetched_replies_at.nil? || fetched_replies_at <= FETCH_REPLIES_DEBOUNCE.ago
)
end
Expand Down

0 comments on commit e712283

Please sign in to comment.