summaryrefslogtreecommitdiff
path: root/cache
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-16 22:48:32 +0200
committerewy <ewy0@protonmail.com>2026-04-16 22:48:32 +0200
commitfbdc2b9d849913ccf8dd7a9001012ce2d28cbd2f (patch)
treef2e08dfcae638a42424742d914053ce2607ab76a /cache
parent6a22a1ee7bfd1fbd34486a224db98eb6aead5c3e (diff)
when reindexing in --all, only index "added" sources
Diffstat (limited to 'cache')
-rw-r--r--cache/cache.go16
-rw-r--r--cache/cache_test.go14
2 files changed, 30 insertions, 0 deletions
diff --git a/cache/cache.go b/cache/cache.go
index ae2d081..98bdbe8 100644
--- a/cache/cache.go
+++ b/cache/cache.go
@@ -111,3 +111,19 @@ func LoadState(f fs.FS, cache Cache, indexers []model.Indexer, runners []model.R
}
return model.NewState(f, locs, indexers, runners)
}
+
+func (c Cache) Strip(needle Cache) Cache {
+ var result []Entry
+outer:
+ for _, e := range c.Entries {
+ for _, t := range needle.Entries {
+ if t.Path == e.Path {
+ continue outer
+ }
+ }
+ result = append(result, e)
+ }
+ return Cache{
+ Entries: result,
+ }
+}
diff --git a/cache/cache_test.go b/cache/cache_test.go
index fa81974..c140154 100644
--- a/cache/cache_test.go
+++ b/cache/cache_test.go
@@ -77,3 +77,17 @@ func TestFromReader_Comments(t *testing.T) {
Label: "da source",
})
}
+
+func TestStrip(t *testing.T) {
+ c := Cache{Entries: []Entry{{"/asdf/123", ""}, {"xxxxx", "lab"}}}
+ remove := Cache{Entries: []Entry{{"xxxxx", "wronglabel"}}}
+ result := c.Strip(remove)
+ assert.Equal(t, Cache{Entries: []Entry{{"/asdf/123", ""}}}, result)
+}
+
+func TestStrip_Nothing(t *testing.T) {
+ c := Cache{Entries: []Entry{{"/asdf/123", ""}, {"/asdf/123", ""}}}
+ old := Cache{}
+ result := c.Strip(old)
+ assert.Equal(t, c, result)
+}