From 12321f82a7f3fe2012d96981d100db5f5db14e2e Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 18 Nov 2020 21:24:26 -0500 Subject: [PATCH] Update every X minutes with X workers --- config/config.go | 4 +++- config/default.go | 22 +++++++++++++++++++--- default-config.toml | 22 +++++++++++++++++++--- display/feeds.go | 5 +++-- display/private.go | 2 +- feeds/feeds.go | 26 +++++++++++++++++++++++--- 6 files changed, 68 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index 8f988b6..65b2772 100644 --- a/config/config.go +++ b/config/config.go @@ -230,11 +230,13 @@ func Init() error { viper.SetDefault("a-general.page_max_size", 2097152) viper.SetDefault("a-general.page_max_time", 10) viper.SetDefault("a-general.emoji_favicons", false) - viper.SetDefault("a-general.feed_popup", true) viper.SetDefault("keybindings.shift_numbers", "!@#$%^&*()") viper.SetDefault("url-handlers.other", "off") viper.SetDefault("cache.max_size", 0) viper.SetDefault("cache.max_pages", 20) + viper.SetDefault("feeds.popup", true) + viper.SetDefault("feeds.update_interval", 1800) + viper.SetDefault("feeds.workers", 3) viper.SetConfigFile(configPath) viper.SetConfigType("toml") diff --git a/config/default.go b/config/default.go index 556da67..ea8e65f 100644 --- a/config/default.go +++ b/config/default.go @@ -68,9 +68,6 @@ page_max_time = 10 # Whether to replace tab numbers with emoji favicons, which are cached. emoji_favicons = false -# Whether a pop-up appears when viewing a potential feed -feed_popup = true - [auth] # Authentication settings @@ -134,6 +131,25 @@ max_pages = 30 # The maximum number of pages the cache will store # Note that HTTP and HTTPS are treated as separate protocols here. +[feeds] +# For tracking feeds and pages + +# Whether a pop-up appears when viewing a potential feed +popup = true + +# How often to check for new feeds and pages in the background, in seconds. +# Note Amfora will check for updates on browser start anyway. +# Set it to 0 or below to disable this feature. You can still update individual +# feeds manually, or just restart the browser to update all of them. +update_interval = 1800 # 30 mins + +# How many pages/feeds can be checked at the same time when updating. +# If you are tracking many feeds and pages you may want to increase this for +# faster update times. +# Any value below 1 will be corrected to 1. +workers = 3 + + [theme] # This section is for changing the COLORS used in Amfora. # These colors only apply if 'color' is enabled above. diff --git a/default-config.toml b/default-config.toml index 5855c02..0365613 100644 --- a/default-config.toml +++ b/default-config.toml @@ -65,9 +65,6 @@ page_max_time = 10 # Whether to replace tab numbers with emoji favicons, which are cached. emoji_favicons = false -# Whether a pop-up appears when viewing a potential feed -feed_popup = true - [auth] # Authentication settings @@ -131,6 +128,25 @@ max_pages = 30 # The maximum number of pages the cache will store # Note that HTTP and HTTPS are treated as separate protocols here. +[feeds] +# For tracking feeds and pages + +# Whether a pop-up appears when viewing a potential feed +popup = true + +# How often to check for new feeds and pages in the background, in seconds. +# Note Amfora will check for updates on browser start anyway. +# Set it to 0 or below to disable this feature. You can still update individual +# feeds manually, or just restart the browser to update all of them. +update_interval = 1800 # 30 mins + +# How many pages/feeds can be checked at the same time when updating. +# If you are tracking many feeds and pages you may want to increase this for +# faster update times. +# Any value below 1 will be corrected to 1. +workers = 3 + + [theme] # This section is for changing the COLORS used in Amfora. # These colors only apply if 'color' is enabled above. diff --git a/display/feeds.go b/display/feeds.go index 21c04ed..40ea59a 100644 --- a/display/feeds.go +++ b/display/feeds.go @@ -43,8 +43,9 @@ func Feeds(t *tab) { logger.Log.Println("started rendering feeds page") - feedPageRaw := "# Feeds & Pages\n\nUpdates" + strings.Repeat(" ", 80-25) + "[Newest -> Oldest]\n" + - strings.Repeat("-", 80) + "\nSee the help (by pressing ?) for details on how to use this page.\n\n" + feedPageRaw := "# Feeds & Pages\n\n" + + "See the help (by pressing ?) for details on how to use this page.\n\n" + + "If you just opened Amfora then updates will appear incrementally. Reload the page to see them.\n" // curDay represents what day of posts the loop is on. // It only goes backwards in time. diff --git a/display/private.go b/display/private.go index 6d06d69..69b5200 100644 --- a/display/private.go +++ b/display/private.go @@ -338,7 +338,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) { t.mode = tabModeDone go func(p *structs.Page) { - if b && t.hasContent() && !feeds.IsTracked(s) && viper.GetBool("a-general.feed_popup") { + if b && t.hasContent() && !feeds.IsTracked(s) && viper.GetBool("feeds.popup") { // The current page might be an untracked feed, and the user wants // to be notified in such cases. diff --git a/feeds/feeds.go b/feeds/feeds.go index a813eff..cb0b0bf 100644 --- a/feeds/feeds.go +++ b/feeds/feeds.go @@ -21,6 +21,7 @@ import ( "github.com/makeworld-the-better-one/amfora/logger" "github.com/makeworld-the-better-one/go-gemini" "github.com/mmcdole/gofeed" + "github.com/spf13/viper" ) // TODO: Test for deadlocks and whether there should be more @@ -60,7 +61,21 @@ func Init() error { } LastUpdated = time.Now() - go updateAll() + + if viper.GetInt("feeds.update_interval") > 0 { + // Update feeds and pages every so often + go func() { + for { + updateAll() + time.Sleep(time.Duration(viper.GetInt("feeds.update_interval")) * time.Second) + } + }() + } else { + // User disabled automatic feed/page updates + // So just update once at the beginning + go updateAll() + } + return nil } @@ -288,8 +303,13 @@ func updateAll() { return } - // Start 2 workers, waiting for jobs - for w := 0; w < 2; w++ { + numWorkers := viper.GetInt("feed.workers") + if numWorkers < 1 { + numWorkers = 1 + } + + // Start workers, waiting for jobs + for w := 0; w < numWorkers; w++ { wg.Add(1) go func(i int) { logger.Log.Println("started worker", i)