Fix Processed images count regression for multiple languages

Fixes #11002
This commit is contained in:
Bjørn Erik Pedersen
2023-05-28 11:35:00 +02:00
parent 43f1282e73
commit fd099331ec
8 changed files with 83 additions and 24 deletions

View File

@@ -26,16 +26,27 @@ import (
"github.com/gohugoio/hugo/helpers"
)
type imageCache struct {
// ImageCache is a cache for image resources. The backing caches are shared between all sites.
type ImageCache struct {
pathSpec *helpers.PathSpec
fileCache *filecache.Cache
*imageCacheStore
}
type imageCacheStore struct {
mu sync.RWMutex
store map[string]*resourceAdapter
}
func (c *imageCache) deleteIfContains(s string) {
// WithPathSpec returns a copy of the ImageCache with the given PathSpec set.
func (c ImageCache) WithPathSpec(ps *helpers.PathSpec) *ImageCache {
c.pathSpec = ps
return &c
}
func (c *ImageCache) deleteIfContains(s string) {
c.mu.Lock()
defer c.mu.Unlock()
s = c.normalizeKeyBase(s)
@@ -48,21 +59,21 @@ func (c *imageCache) deleteIfContains(s string) {
// The cache key is a lowercase path with Unix style slashes and it always starts with
// a leading slash.
func (c *imageCache) normalizeKey(key string) string {
func (c *ImageCache) normalizeKey(key string) string {
return "/" + c.normalizeKeyBase(key)
}
func (c *imageCache) normalizeKeyBase(key string) string {
func (c *ImageCache) normalizeKeyBase(key string) string {
return strings.Trim(strings.ToLower(filepath.ToSlash(key)), "/")
}
func (c *imageCache) clear() {
func (c *ImageCache) clear() {
c.mu.Lock()
defer c.mu.Unlock()
c.store = make(map[string]*resourceAdapter)
}
func (c *imageCache) getOrCreate(
func (c *ImageCache) getOrCreate(
parent *imageResource, conf images.ImageConfig,
createImage func() (*imageResource, image.Image, error)) (*resourceAdapter, error) {
relTarget := parent.relTargetPathFromConfig(conf)
@@ -163,6 +174,6 @@ func (c *imageCache) getOrCreate(
return imgAdapter, nil
}
func newImageCache(fileCache *filecache.Cache, ps *helpers.PathSpec) *imageCache {
return &imageCache{fileCache: fileCache, pathSpec: ps, store: make(map[string]*resourceAdapter)}
func newImageCache(fileCache *filecache.Cache, ps *helpers.PathSpec) *ImageCache {
return &ImageCache{fileCache: fileCache, pathSpec: ps, imageCacheStore: &imageCacheStore{store: make(map[string]*resourceAdapter)}}
}