Skip to content

Commit

Permalink
Add FORCE_REFRESH_INTERVAL config option
Browse files Browse the repository at this point in the history
  • Loading branch information
notsmarthuman authored Jan 3, 2024
1 parent a1879ea commit 4590da2
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 20 deletions.
35 changes: 35 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,41 @@ func TestPollingFrequency(t *testing.T) {
}
}

func TestDefautForceRefreshInterval(t *testing.T) {
os.Clearenv()

parser := NewParser()
opts, err := parser.ParseEnvironmentVariables()
if err != nil {
t.Fatalf(`Parsing failure: %v`, err)
}

expected := defaultForceRefreshInterval
result := opts.ForceRefreshInterval()

if result != expected {
t.Fatalf(`Unexpected FORCE_REFRESH_INTERVAL value, got %v instead of %v`, result, expected)
}
}

func TestForceRefreshInterval(t *testing.T) {
os.Clearenv()
os.Setenv("FORCE_REFRESH_INTERVAL", "42")

parser := NewParser()
opts, err := parser.ParseEnvironmentVariables()
if err != nil {
t.Fatalf(`Parsing failure: %v`, err)
}

expected := 42
result := opts.ForceRefreshInterval()

if result != expected {
t.Fatalf(`Unexpected FORCE_REFRESH_INTERVAL value, got %v instead of %v`, result, expected)
}
}

func TestDefaultBatchSizeValue(t *testing.T) {
os.Clearenv()

Expand Down
9 changes: 9 additions & 0 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
defaultBasePath = ""
defaultWorkerPoolSize = 5
defaultPollingFrequency = 60
defaultForceRefreshInterval = 30
defaultBatchSize = 100
defaultPollingScheduler = "round_robin"
defaultSchedulerEntryFrequencyMinInterval = 5
Expand Down Expand Up @@ -122,6 +123,7 @@ type Options struct {
cleanupArchiveBatchSize int
cleanupRemoveSessionsDays int
pollingFrequency int
forceRefreshInterval int
batchSize int
pollingScheduler string
schedulerEntryFrequencyMinInterval int
Expand Down Expand Up @@ -200,6 +202,7 @@ func NewOptions() *Options {
cleanupArchiveBatchSize: defaultCleanupArchiveBatchSize,
cleanupRemoveSessionsDays: defaultCleanupRemoveSessionsDays,
pollingFrequency: defaultPollingFrequency,
forceRefreshInterval: defaultForceRefreshInterval,
batchSize: defaultBatchSize,
pollingScheduler: defaultPollingScheduler,
schedulerEntryFrequencyMinInterval: defaultSchedulerEntryFrequencyMinInterval,
Expand Down Expand Up @@ -378,6 +381,11 @@ func (o *Options) PollingFrequency() int {
return o.pollingFrequency
}

// ForceRefreshInterval returns the force refresh interval
func (o *Options) ForceRefreshInterval() int {
return o.forceRefreshInterval
}

// BatchSize returns the number of feeds to send for background processing.
func (o *Options) BatchSize() int {
return o.batchSize
Expand Down Expand Up @@ -663,6 +671,7 @@ func (o *Options) SortedOptions(redactSecret bool) []*Option {
"OAUTH2_USER_CREATION": o.oauth2UserCreationAllowed,
"POCKET_CONSUMER_KEY": redactSecretValue(o.pocketConsumerKey, redactSecret),
"POLLING_FREQUENCY": o.pollingFrequency,
"FORCE_REFRESH_INTERVAL": o.forceRefreshInterval,
"POLLING_PARSING_ERROR_LIMIT": o.pollingParsingErrorLimit,
"POLLING_SCHEDULER": o.pollingScheduler,
"PROXY_HTTP_CLIENT_TIMEOUT": o.proxyHTTPClientTimeout,
Expand Down
2 changes: 2 additions & 0 deletions internal/config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func (p *Parser) parseLines(lines []string) (err error) {
p.opts.workerPoolSize = parseInt(value, defaultWorkerPoolSize)
case "POLLING_FREQUENCY":
p.opts.pollingFrequency = parseInt(value, defaultPollingFrequency)
case "FORCE_REFRESH_INTERVAL":
p.opts.forceRefreshInterval = parseInt(value, defaultForceRefreshInterval)
case "BATCH_SIZE":
p.opts.batchSize = parseInt(value, defaultBatchSize)
case "POLLING_SCHEDULER":
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"vor %d Jahr",
"vor %d Jahren"
],
"alert.too_many_feeds_refresh": "Sie haben zu viele Aktualisierungen ausgelöst. Bitte warten Sie 30 Minuten, bevor Sie es erneut versuchen.",
"alert.too_many_feeds_refresh": [
"Sie haben zu viele Aktualisierungen ausgelöst. Bitte warten Sie %d Minute, bevor Sie es erneut versuchen.",
"Sie haben zu viele Aktualisierungen ausgelöst. Bitte warten Sie %d Minuten, bevor Sie es erneut versuchen."
],
"alert.background_feed_refresh": "Alle Abonnements werden derzeit im Hintergrund aktualisiert. Sie können Miniflux weiterhin benutzen, während dieser Prozess ausgeführt wird.",
"error.http_response_too_large": "Die HTTP-Antwort ist zu groß. Sie könnten die Grenze für die Größe der HTTP-Antwort in den globalen Einstellungen erhöhen (benötigt einen Neustart des Servers)",
"error.http_body_read": "Der HTTP-Inhalt kann nicht gelesen werden: %v",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/el_EL.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"πριν %d έτος",
"πριν %d έτη"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d year ago",
"%d years ago"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"hace %d año",
"hace %d años"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/fi_FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d vuosi sitten",
"%d vuotta sitten"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"il y a %d an",
"il y a %d ans"
],
"alert.too_many_feeds_refresh": "Vous avez déclenché trop d'actualisations de flux. Veuillez attendre 30 minutes avant de réessayer.",
"alert.too_many_feeds_refresh": [
"Vous avez déclenché trop d'actualisations de flux. Veuillez attendre %d minute avant de réessayer.",
"Vous avez déclenché trop d'actualisations de flux. Veuillez attendre %d minutes avant de réessayer."
],
"alert.background_feed_refresh": "Les abonnements sont en cours d'actualisation en arrière-plan. Vous pouvez continuer à naviguer dans l'application.",
"error.http_response_too_large": "La réponse HTTP est trop volumineuse. Vous pouvez augmenter la limite de taille de réponse HTTP dans les paramètres de l'application (redémarrage de l'application nécessaire).",
"error.http_body_read": "Impossible de lire le corps de la réponse HTTP : %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d साल पहले",
"%d वर्षों पहले"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/id_ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@
"time_elapsed.years": [
"%d tahun yang lalu"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d anno fa",
"%d anni fa"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d 年前",
"%d 年前"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/nl_NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d jaar geleden",
"%d jaar geleden"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,10 @@
"%d lat temu",
"%d lat temu"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"há %d ano",
"há %d anos"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,10 @@
"%d года назад",
"%d лет назад"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/tr_TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d yıl önce",
"%d yıl önce"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/uk_UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@
"%d роки тому",
"%d років тому"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@
"time_elapsed.years": [
"%d 年前"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
5 changes: 4 additions & 1 deletion internal/locale/translations/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@
"%d 年前",
"%d 年前"
],
"alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
"alert.too_many_feeds_refresh": [
"You have triggered too many feed refreshes. Please wait %d minute before trying again.",
"You have triggered too many feed refreshes. Please wait %d minutes before trying again."
],
"alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
"error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
"error.http_body_read": "Unable to read the HTTP body: %v.",
Expand Down
6 changes: 4 additions & 2 deletions internal/ui/feed_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"time"

"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/http/request"
"miniflux.app/v2/internal/http/response/html"
"miniflux.app/v2/internal/http/route"
Expand Down Expand Up @@ -37,8 +38,9 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
sess := session.New(h.store, request.SessionID(r))

// Avoid accidental and excessive refreshes.
if time.Now().UTC().Unix()-request.LastForceRefresh(r) < 1800 {
sess.NewFlashErrorMessage(printer.Printf("alert.too_many_feeds_refresh"))
if time.Now().UTC().Unix()-request.LastForceRefresh(r) < int64(config.Opts.ForceRefreshInterval())*60 {
time := config.Opts.ForceRefreshInterval()
sess.NewFlashErrorMessage(printer.Plural("alert.too_many_feeds_refresh", time, time))
} else {
// We allow the end-user to force refresh all its feeds
// without taking into consideration the number of errors.
Expand Down
4 changes: 4 additions & 0 deletions miniflux.1
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ Refresh interval in minutes for feeds\&.
.br
Default is 60 minutes\&.
.TP
.B FORCE_REFRESH_INTERVAL
The minimum interval for manual refresh\&.
.br
Default is 30 minutes\&.
.B BATCH_SIZE
Number of feeds to send to the queue for each interval\&.
.br
Expand Down

0 comments on commit 4590da2

Please sign in to comment.