aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/state.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-26 00:23:49 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-26 00:23:49 +0200
commita83e9bd36fc6a934553d93cbcc0edb120321f971 (patch)
treea9cc04ca3a0f8392f6ccbf470b323794e535ae7a /internal/feed/state.go
parent87fd0ad3e9309064fe9fda373035f5ce127ae8d8 (diff)
downloadfeed2imap-go-a83e9bd36fc6a934553d93cbcc0edb120321f971.tar.gz
feed2imap-go-a83e9bd36fc6a934553d93cbcc0edb120321f971.tar.bz2
feed2imap-go-a83e9bd36fc6a934553d93cbcc0edb120321f971.zip
Filtering from cache
Diffstat (limited to '')
-rw-r--r--internal/feed/state.go39
1 files changed, 38 insertions, 1 deletions
diff --git a/internal/feed/state.go b/internal/feed/state.go
index 2a0a1e1..8ec8dfd 100644
--- a/internal/feed/state.go
+++ b/internal/feed/state.go
@@ -4,6 +4,7 @@ import (
"sync"
"github.com/Necoro/feed2imap-go/pkg/config"
+ "github.com/Necoro/feed2imap-go/pkg/log"
)
type State struct {
@@ -50,7 +51,7 @@ func (state *State) Fetch() int {
ctr := 0
for _, feed := range state.feeds {
- success := feed.Success()
+ success := feed.FetchSuccessful()
feed.cached.Checked(!success)
if success {
@@ -61,6 +62,42 @@ func (state *State) Fetch() int {
return ctr
}
+func filterFeed(feed *Feed, group *sync.WaitGroup) {
+ if len(feed.items) > 0 {
+ origLen := len(feed.items)
+
+ log.Debugf("Filtering %s. Starting with %d items", feed.Name, origLen)
+ items := feed.cached.filterItems(feed.items)
+ feed.items = items
+
+ newLen := len(feed.items)
+ if newLen < origLen {
+ log.Printf("Filtered %s. Reduced from %d to %d items.", feed.Name, origLen, newLen)
+ } else {
+ log.Printf("Filtered %s, no reduction.", feed.Name)
+ }
+
+ } else {
+ log.Debugf("No items for %s. No filtering.", feed.Name)
+ }
+
+ if group != nil {
+ // group is nil in debug case
+ group.Done()
+ }
+}
+
+func (state *State) Filter() {
+ if log.IsDebug() {
+ // single threaded for better output
+ state.Foreach(func(f *Feed) {
+ filterFeed(f, nil)
+ })
+ } else {
+ state.ForeachGo(filterFeed)
+ }
+}
+
func NewState(cfg *config.Config) *State {
state := State{
feeds: map[string]*Feed{},