diff options
Diffstat (limited to 'internal/feed/cache')
-rw-r--r-- | internal/feed/cache/cache.go | 12 | ||||
-rw-r--r-- | internal/feed/cache/cache_v1.go | 7 | ||||
-rw-r--r-- | internal/feed/cache/state.go | 4 |
3 files changed, 13 insertions, 10 deletions
diff --git a/internal/feed/cache/cache.go b/internal/feed/cache/cache.go index e7fe673..e69e8f3 100644 --- a/internal/feed/cache/cache.go +++ b/internal/feed/cache/cache.go @@ -50,7 +50,7 @@ type CachedFeed interface { Feed() *feed.Feed } -func cacheForVersion(version Version) (Impl, error) { +func forVersion(version Version) (Impl, error) { switch version { case v1Version: return newV1Cache(), nil @@ -124,8 +124,8 @@ func (cache *Cache) Unlock() error { return nil } -func newCache() (Cache, error) { - cache, err := cacheForVersion(currentVersion) +func create() (Cache, error) { + cache, err := forVersion(currentVersion) if err != nil { return Cache{}, err } @@ -135,12 +135,12 @@ func newCache() (Cache, error) { }, nil } -func LoadCache(fileName string) (Cache, error) { +func Load(fileName string) (Cache, error) { f, err := os.Open(fileName) if err != nil { if errors.Is(err, os.ErrNotExist) { // no cache there yet -- make new - return newCache() + return create() } return Cache{}, fmt.Errorf("opening cache at '%s': %w", fileName, err) } @@ -159,7 +159,7 @@ func LoadCache(fileName string) (Cache, error) { return Cache{}, fmt.Errorf("reading from '%s': %w", fileName, err) } - cache, err := cacheForVersion(Version(version)) + cache, err := forVersion(Version(version)) if err != nil { return Cache{}, err } diff --git a/internal/feed/cache/cache_v1.go b/internal/feed/cache/cache_v1.go index d754b00..439846f 100644 --- a/internal/feed/cache/cache_v1.go +++ b/internal/feed/cache/cache_v1.go @@ -208,7 +208,7 @@ func (cache *v1Cache) cachedFeed(f *feed.Feed) CachedFeed { return cf } -func newCachedItem(item *feed.Item) cachedItem { +func (cf *cachedFeed) cachedItem(item *feed.Item) cachedItem { var ci cachedItem ci.ID = item.ID @@ -245,8 +245,11 @@ 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) + // remove complete duplicates on the go - cacheItems[newCachedItem(&items[idx])] = &items[idx] + cacheItems[ci] = i } log.Debugf("%d items after deduplication", len(cacheItems)) diff --git a/internal/feed/cache/state.go b/internal/feed/cache/state.go index c2e7de8..1c911d7 100644 --- a/internal/feed/cache/state.go +++ b/internal/feed/cache/state.go @@ -43,9 +43,9 @@ func (state *State) LoadCache(fileName string, forceNew bool) error { ) if forceNew { - cache, err = newCache() + cache, err = create() } else { - cache, err = LoadCache(fileName) + cache, err = Load(fileName) } if err != nil { |