aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/feed.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 11:27:34 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 11:27:34 +0200
commitd21881150c09986571a563eaf30bc1687787e63f (patch)
treea5da8a3fdb91a3dcf806b704e20b16616a934801 /internal/feed/feed.go
parentc08aff21cd67cc27926a4cb1ca72ffe67e015ebf (diff)
downloadfeed2imap-go-d21881150c09986571a563eaf30bc1687787e63f.tar.gz
feed2imap-go-d21881150c09986571a563eaf30bc1687787e63f.tar.bz2
feed2imap-go-d21881150c09986571a563eaf30bc1687787e63f.zip
Improved caching
Diffstat (limited to '')
-rw-r--r--internal/feed/feed.go64
1 files changed, 59 insertions, 5 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
index cd906a2..5af4188 100644
--- a/internal/feed/feed.go
+++ b/internal/feed/feed.go
@@ -3,10 +3,13 @@ package feed
import (
"fmt"
"strings"
+ "sync"
+ "time"
"github.com/mmcdole/gofeed"
"github.com/Necoro/feed2imap-go/internal/config"
+ "github.com/Necoro/feed2imap-go/internal/log"
)
type Feed struct {
@@ -14,8 +17,9 @@ type Feed struct {
Target []string
Url string
config.Options
- feed *gofeed.Feed
- items []feeditem
+ feed *gofeed.Feed
+ items []feeditem
+ cached CachedFeed
}
type feeditem struct {
@@ -23,9 +27,18 @@ type feeditem struct {
*gofeed.Item
}
-type Feeds map[string]*Feed
+type Feeds struct {
+ feeds map[string]*Feed
+ cache Cache
+}
+
+func NewFeeds() *Feeds {
+ return &Feeds{
+ feeds: map[string]*Feed{},
+ }
+}
-func (f Feeds) String() string {
+func (feeds *Feeds) String() string {
var b strings.Builder
app := func(a ...interface{}) {
_, _ = fmt.Fprint(&b, a...)
@@ -33,7 +46,7 @@ func (f Feeds) String() string {
app("Feeds [")
first := true
- for k, v := range f {
+ for k, v := range feeds.feeds {
if !first {
app(", ")
}
@@ -49,3 +62,44 @@ func (f Feeds) String() string {
return b.String()
}
+
+func (feeds *Feeds) Len() int {
+ return len(feeds.feeds)
+}
+
+func (feeds *Feeds) Contains(name string) bool {
+ _, ok := feeds.feeds[name]
+ return ok
+}
+
+func (feeds *Feeds) Set(name string, feed *Feed) {
+ feeds.feeds[name] = feed
+}
+
+func (feeds *Feeds) Foreach(f func(*Feed)) {
+ for _, feed := range feeds.feeds {
+ f(feed)
+ }
+}
+
+func (feeds *Feeds) ForeachGo(goFunc func(*Feed, *sync.WaitGroup)) {
+ var wg sync.WaitGroup
+ wg.Add(feeds.Len())
+
+ for _, feed := range feeds.feeds {
+ go goFunc(feed, &wg)
+ }
+ wg.Wait()
+}
+
+func (feed *Feed) NeedsUpdate(updateTime time.Time) bool {
+ if !updateTime.IsZero() && int(time.Since(updateTime).Hours()) >= feed.MinFreq {
+ log.Printf("Feed '%s' does not need updating, skipping.", feed.Name)
+ return false
+ }
+ return true
+}
+
+func (feed *Feed) Success() bool {
+ return feed.feed != nil
+}
it/pkg/version/version.go?h=v0.5.2&id=47b2f99d09a0dd30ecceb2190773bb6cc337f6d2&follow=1'>Release v0.2.0v0.2.0René 'Necoro' Neumann2-2/+6 2020-05-10Fix building cacheRené 'Necoro' Neumann1-1/+3 2020-05-10Update READMERené 'Necoro' Neumann1-5/+44 2020-05-10Ignore 'dist' folder and build productsRené 'Necoro' Neumann1-0/+2 2020-05-08Print item hashes in debug modeRené 'Necoro' Neumann1-1/+7 2020-05-07Improve html renderingRené 'Necoro' Neumann2-53/+32 2020-05-07Do not assume items to be new when their published date is newer than the las...René 'Necoro' Neumann2-7/+1 2020-05-07Updating some depsRené 'Necoro' Neumann2-2/+7 2020-05-07Better detection if a text starts with html or notRené 'Necoro' Neumann2-4/+13 2020-05-07go fmtRené 'Necoro' Neumann1-3/+2 2020-05-07Add header X-Feed2Imap-GUIDRené 'Necoro' Neumann3-1/+7 2020-05-07update changelogRené 'Necoro' Neumann1-0/+1 2020-05-07FixRené 'Necoro' Neumann1-1/+1 2020-05-07Unified publishedDate and updatedDate into one (just as the old feed2imap...)René 'Necoro' Neumann5-21/+32 2020-05-06Print version during startupRené 'Necoro' Neumann1-1/+1 2020-05-06Improve templateRené 'Necoro' Neumann3-20/+28 2020-05-05Fix pipelineRené 'Necoro' Neumann1-2/+5 2020-05-05Make changelog a part of the release pipeline (untested)René 'Necoro' Neumann2-0/+12