aboutsummaryrefslogtreecommitdiff
path: root/internal/feed
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 17:50:12 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 17:51:42 +0200
commit60ff245e6d965785d54a212b2a4ddd9b16159460 (patch)
treef07bf776739213447f616901e1803fdd65845da5 /internal/feed
parent8c134b0ece0da2d774e2bad4df35803d3c30f500 (diff)
downloadfeed2imap-go-60ff245e6d965785d54a212b2a4ddd9b16159460.tar.gz
feed2imap-go-60ff245e6d965785d54a212b2a4ddd9b16159460.tar.bz2
feed2imap-go-60ff245e6d965785d54a212b2a4ddd9b16159460.zip
Remove undue feeds
Diffstat (limited to 'internal/feed')
-rw-r--r--internal/feed/cache.go2
-rw-r--r--internal/feed/cache_v1.go4
-rw-r--r--internal/feed/feed.go5
-rw-r--r--internal/feed/state.go8
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)
+ }
+ }
+}
>-53/+34 2006-12-13Small layout adjustments to summary and blob viewLars Hjemli3-5/+13 2006-12-13Add display of tree content w/ui-tree.cLars Hjemli9-8/+113 2006-12-12cache_lock: do xstrdup/free on lockfileLars Hjemli1-1/+2 2006-12-11Don't truncate valid cachefilesLars Hjemli3-4/+16 2006-12-11Move global variables + callback functions into shared.cLars Hjemli4-82/+86 2006-12-11Move functions for generic object output into ui-view.cLars Hjemli4-34/+43 2006-12-11Move log-functions into ui-log.cLars Hjemli5-111/+121 2006-12-11Move repo summary functions into ui-summary.cLars Hjemli4-47/+59 2006-12-11Move functions for repolist output into ui-repolist.cLars Hjemli5-70/+90 2006-12-11Move common output-functions into ui-shared.cLars Hjemli4-82/+99 2006-12-11Rename config.c to parsing.c + move cgit_parse_query from cgit.c to parsing.cLars Hjemli4-28/+29 2006-12-11Avoid infinite loops in caching layerLars Hjemli3-14/+31 2006-12-11Let 'make install' clear all cachefilesLars Hjemli1-0/+2 2006-12-11Fix cache algorithm loopholeLars Hjemli3-11/+16 2006-12-10Add version identifier in generated filesLars Hjemli2-9/+14 2006-12-10Add license file and copyright noticesLars Hjemli5-0/+372 2006-12-10Add caching infrastructureLars Hjemli9-28/+353