From 60ff245e6d965785d54a212b2a4ddd9b16159460 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sat, 25 Apr 2020 17:50:12 +0200 Subject: Remove undue feeds --- internal/feed/cache.go | 2 ++ internal/feed/cache_v1.go | 4 ++++ internal/feed/feed.go | 5 ++++- internal/feed/state.go | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'internal') diff --git a/internal/feed/cache.go b/internal/feed/cache.go index 4a0bfe7..735a7d6 100644 --- a/internal/feed/cache.go +++ b/internal/feed/cache.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "os" + "time" "github.com/Necoro/feed2imap-go/pkg/log" ) @@ -25,6 +26,7 @@ type Cache interface { type CachedFeed interface { Checked(withFailure bool) Failures() uint + Last() time.Time } func cacheForVersion(version Version) (Cache, error) { diff --git a/internal/feed/cache_v1.go b/internal/feed/cache_v1.go index 3d46084..1c53239 100644 --- a/internal/feed/cache_v1.go +++ b/internal/feed/cache_v1.go @@ -51,6 +51,10 @@ func (cf *cachedFeed) Failures() uint { return cf.NumFailures } +func (cf *cachedFeed) Last() time.Time { + return cf.LastCheck +} + func (cache *v1Cache) Version() Version { return v1Version } diff --git a/internal/feed/feed.go b/internal/feed/feed.go index d087d3a..4ee2875 100644 --- a/internal/feed/feed.go +++ b/internal/feed/feed.go @@ -34,7 +34,10 @@ func (feed *Feed) descriptor() feedDescriptor { } func (feed *Feed) NeedsUpdate(updateTime time.Time) bool { - if !updateTime.IsZero() && int(time.Since(updateTime).Hours()) >= *feed.MinFreq { + if *feed.MinFreq == 0 { // shortcut + return true + } + if !updateTime.IsZero() && int(time.Since(updateTime).Hours()) < *feed.MinFreq { log.Printf("Feed '%s' does not need updating, skipping.", feed.Name) return false } diff --git a/internal/feed/state.go b/internal/feed/state.go index 9a6f836..8efef5e 100644 --- a/internal/feed/state.go +++ b/internal/feed/state.go @@ -74,3 +74,11 @@ func NewState(cfg *config.Config) *State { return &state } + +func (state *State) RemoveUndue() { + for name, feed := range state.feeds { + if !feed.NeedsUpdate(feed.cached.Last()) { + delete(state.feeds, name) + } + } +} -- cgit v1.2.3-70-g09d2 ame='q' value=''/>
path: root/src/platform (unfollow)
Commit message (Expand)AuthorFilesLines
2014-03-20man: Document multiple keys in env varJason A. Donenfeld1-1/+3
2014-03-20clip: don't race between pass instances in restoreJason A. Donenfeld1-2/+4
2014-03-20Style.Jason A. Donenfeld1-3/+1
2014-03-19Simplify exports.Jason A. Donenfeld1-4/+3
2014-03-19Copyright noticeJason A. Donenfeld1-1/+1
2014-03-19Team pass: enable multiple keys and per directoryJason A. Donenfeld2-40/+75
2014-03-18Shred shm files.Jason A. Donenfeld3-1/+4
2014-03-18Do not compress passwords.Jason A. Donenfeld1-1/+1
2013-09-14Use a glob in the pattern match instead of using two comparisons for [yY].Chris Down1-1/+1
2013-09-14Rephrase awkward/confusing message about enabling echo during password entry.Chris Down1-3/+3
2013-09-14Fix directory traversal for reencryption when $PREFIX is a symlinkBrian Shore1-1/+1
2013-08-26Makefile: Do not install bash completion to /etcLukas Fleischer1-3/+2
2013-05-22check if a passfile exists before checking for directoryBrian Mattern1-13/+12