From 004b6943906471cff0d0232040d24cff6cb89e6b Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Sat, 20 Apr 2024 11:05:35 +0200 Subject: Fix partial rebuilds for SCSS fetched with GetMatch and similar Fixes #12395 --- cache/dynacache/dynacache.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'cache/dynacache/dynacache.go') diff --git a/cache/dynacache/dynacache.go b/cache/dynacache/dynacache.go index eab251e5d..e79de5a5b 100644 --- a/cache/dynacache/dynacache.go +++ b/cache/dynacache/dynacache.go @@ -140,16 +140,25 @@ func (c *Cache) DrainEvictedIdentities() []identity.Identity { } // ClearMatching clears all partition for which the predicate returns true. -func (c *Cache) ClearMatching(predicate func(k, v any) bool) { +func (c *Cache) ClearMatching(predicatePartition func(k string, p PartitionManager) bool, predicateValue func(k, v any) bool) { + if predicatePartition == nil { + predicatePartition = func(k string, p PartitionManager) bool { return true } + } + if predicateValue == nil { + panic("nil predicateValue") + } g := rungroup.Run[PartitionManager](context.Background(), rungroup.Config[PartitionManager]{ NumWorkers: len(c.partitions), Handle: func(ctx context.Context, partition PartitionManager) error { - partition.clearMatching(predicate) + partition.clearMatching(predicateValue) return nil }, }) - for _, p := range c.partitions { + for k, p := range c.partitions { + if !predicatePartition(k, p) { + continue + } g.Enqueue(p) } @@ -356,6 +365,7 @@ func GetOrCreatePartition[K comparable, V any](c *Cache, name string, opts Optio trace: c.opts.Log.Logger().WithLevel(logg.LevelTrace).WithField("partition", name), opts: opts, } + c.partitions[name] = partition return partition -- cgit v1.2.3