diff options
Diffstat (limited to '')
-rw-r--r-- | internal/feed/cache.go | 2 | ||||
-rw-r--r-- | internal/feed/cache_v1.go | 4 | ||||
-rw-r--r-- | internal/feed/feed.go | 5 | ||||
-rw-r--r-- | internal/feed/state.go | 8 |
4 files changed, 18 insertions, 1 deletions
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) + } + } +} |