all: Replace RWMutex struct caches with ConcurrentMap

This commit is contained in:
Bjørn Erik Pedersen
2026-05-23 12:12:51 +02:00
parent d8c70218b7
commit c4bbc2805c
13 changed files with 66 additions and 168 deletions
+4 -13
View File
@@ -31,6 +31,7 @@ import (
"github.com/gohugoio/hugo/helpers"
"github.com/BurntSushi/locker"
"github.com/bep/helpers/maphelpers"
"github.com/spf13/afero"
)
@@ -56,8 +57,7 @@ type Cache struct {
}
type lockTracker struct {
seenMu sync.RWMutex
seen map[string]struct{}
seen *maphelpers.ConcurrentSet[string]
*locker.Locker
}
@@ -65,16 +65,7 @@ type lockTracker struct {
// Lock tracks the ids in use. We use this information to do garbage collection
// after a Hugo build.
func (l *lockTracker) Lock(id string) {
l.seenMu.RLock()
if _, seen := l.seen[id]; !seen {
l.seenMu.RUnlock()
l.seenMu.Lock()
l.seen[id] = struct{}{}
l.seenMu.Unlock()
} else {
l.seenMu.RUnlock()
}
l.seen.AddIfAbsent(id)
l.Locker.Lock(id)
}
@@ -92,7 +83,7 @@ func NewCache(fs afero.Fs, cfg FileCacheConfig) *Cache {
return &Cache{
Fs: fs,
entryLocker: &lockTracker{Locker: locker.NewLocker(), seen: make(map[string]struct{})},
entryLocker: &lockTracker{Locker: locker.NewLocker(), seen: maphelpers.NewConcurrentSet[string]()},
cfg: cfg,
}
}
+2 -3
View File
@@ -93,10 +93,9 @@ func (c *Cache) Prune(force bool) (int, error) {
shouldRemove := force || c.isExpired(info.ModTime())
if !shouldRemove && len(c.entryLocker.seen) > 0 {
if !shouldRemove && c.entryLocker.seen.Len() > 0 {
// Remove it if it's not been touched/used in the last build.
_, seen := c.entryLocker.seen[name]
shouldRemove = !seen
shouldRemove = !c.entryLocker.seen.Has(name)
}
if shouldRemove {