From e712283c9a9dbdbe221059b4068c471a0505d15b Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 14 Oct 2024 19:57:54 -0700 Subject: [PATCH] add configurability via .env file --- .env.production.sample | 9 +++++++++ app/models/concerns/status/fetch_replies_concern.rb | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.env.production.sample b/.env.production.sample index e8c1529f920c08..6e109a64a978a2 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -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 diff --git a/app/models/concerns/status/fetch_replies_concern.rb b/app/models/concerns/status/fetch_replies_concern.rb index 696e93ec88555c..62c908840a72e2 100644 --- a/app/models/concerns/status/fetch_replies_concern.rb +++ b/app/models/concerns/status/fetch_replies_concern.rb @@ -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..) } @@ -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