aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/cache
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-02-29 12:47:23 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-05-12 23:10:36 +0200
commit5f40b4b394d1e768d59cf33ec507451ec45accc5 (patch)
treedbb1a04364d3d4b2cef4f726b361c25bf2921b0b /internal/feed/cache
parent503fa62794ccca8e27cde99f3fbabf41adad5f3f (diff)
downloadfeed2imap-go-5f40b4b394d1e768d59cf33ec507451ec45accc5.tar.gz
feed2imap-go-5f40b4b394d1e768d59cf33ec507451ec45accc5.tar.bz2
feed2imap-go-5f40b4b394d1e768d59cf33ec507451ec45accc5.zip
Small refactoring
Diffstat (limited to '')
-rw-r--r--internal/feed/cache/v1.go17
1 files changed, 9 insertions, 8 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
}