diff options
Diffstat (limited to '')
-rw-r--r-- | internal/feed/cache/v1.go | 17 | ||||
-rw-r--r-- | internal/feed/item.go | 9 | ||||
-rw-r--r-- | internal/feed/parse.go | 3 |
3 files changed, 18 insertions, 11 deletions
diff --git a/internal/feed/cache/v1.go b/internal/feed/cache/v1.go index 8091b28..aecb242 100644 --- a/internal/feed/cache/v1.go +++ b/internal/feed/cache/v1.go @@ -7,13 +7,12 @@ import ( "encoding/hex" "fmt" "io" + "slices" "sort" "strconv" "strings" "time" - "github.com/google/uuid" - "github.com/Necoro/feed2imap-go/internal/feed" "github.com/Necoro/feed2imap-go/pkg/log" "github.com/Necoro/feed2imap-go/pkg/util" @@ -66,7 +65,7 @@ type cachedItem struct { Date time.Time UpdatedCache time.Time Hash itemHash - ID uuid.UUID + ID feed.ItemID deleted bool } @@ -187,7 +186,7 @@ func (cache *v1Cache) transformTo(v Version) (Impl, error) { } } -func (cache *v1Cache) getItem(id feedId) *cachedFeed { +func (cache *v1Cache) getFeed(id feedId) *cachedFeed { feed, ok := cache.Feeds[id] if !ok { feed = &cachedFeed{} @@ -226,13 +225,13 @@ func (cache *v1Cache) cachedFeed(f *feed.Feed) CachedFeed { cache.Ids[fDescr] = id } - cf := cache.getItem(id) + cf := cache.getFeed(id) cf.feed = f f.SetExtID(id) return cf } -func (cf *cachedFeed) cachedItem(item *feed.Item) cachedItem { +func (cf *cachedFeed) buildCachedItem(item *feed.Item) cachedItem { var ci cachedItem ci.ID = item.ID @@ -268,7 +267,7 @@ func (cf *cachedFeed) Filter(items []feed.Item, ignoreHash, alwaysNew bool) []fe cacheItems := make(map[cachedItem]*feed.Item, len(items)) for idx := range items { i := &items[idx] - ci := cf.cachedItem(i) + ci := cf.buildCachedItem(i) // remove complete duplicates on the go cacheItems[ci] = i @@ -350,7 +349,9 @@ CACHE_ITEMS: log.Debugf("%d items after filtering", len(filtered)) - cf.newItems = append(cacheadd, filterItems(cf.Items)...) + // only the old items (cf.Items) is filtered and trimmed + // this is to ensure that really all new additions are part of the cache + cf.newItems = slices.Concat(cacheadd, filterItems(cf.Items)) return filtered } diff --git a/internal/feed/item.go b/internal/feed/item.go index bc1865a..4482a5c 100644 --- a/internal/feed/item.go +++ b/internal/feed/item.go @@ -20,6 +20,12 @@ type feedImage struct { name string } +type ItemID uuid.UUID + +func newItemID() ItemID { + return ItemID(uuid.New()) +} + type Item struct { *gofeed.Item // access fields implicitly Feed *gofeed.Feed // named explicitly to not shadow common fields with Item @@ -27,9 +33,9 @@ type Item struct { Body string TextBody string UpdateOnly bool + ID ItemID reasons []string images []feedImage - ID uuid.UUID } func (item *Item) DateParsed() *time.Time { @@ -77,6 +83,7 @@ func (item *Item) addImage(img []byte, mime string, name string) int { } func (item *Item) clearImages() { + clear(item.images) item.images = []feedImage{} } diff --git a/internal/feed/parse.go b/internal/feed/parse.go index a471b2d..bc796d3 100644 --- a/internal/feed/parse.go +++ b/internal/feed/parse.go @@ -6,7 +6,6 @@ import ( "os/exec" "github.com/Necoro/gofeed" - "github.com/google/uuid" "github.com/Necoro/feed2imap-go/internal/http" ) @@ -59,7 +58,7 @@ func (feed *Feed) Parse() error { feed.feed = parsedFeed feed.items = make([]Item, len(parsedFeed.Items)) for idx, feedItem := range parsedFeed.Items { - feed.items[idx] = Item{Feed: parsedFeed, feed: feed, Item: feedItem, ID: uuid.New()} + feed.items[idx] = Item{Feed: parsedFeed, feed: feed, Item: feedItem, ID: newItemID()} } return cleanup() } |