Skip to content

Commit 4b04db0

Browse files
committed
resource: Avoid processing and storing same image for each language
Fixes #4231
1 parent 97c1866 commit 4b04db0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

‎resource/image.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (i *Image) doWithImageConfig(action, spec string, f func(src image.Image, c
219219
}
220220

221221
if conf.Rotate != 0 {
222-
// Rotate it befor any scaling to get the dimensions correct.
222+
// Rotate it before any scaling to get the dimensions correct.
223223
src = imaging.Rotate(src, float64(conf.Rotate), color.Transparent)
224224
}
225225

‎resource/image_cache.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ func (c *imageCache) deleteByPrefix(prefix string) {
5151

5252
func (c *imageCache) getOrCreate(
5353
spec *Spec, key string, create func(resourceCacheFilename string) (*Image, error)) (*Image, error) {
54+
55+
relTargetFilename := key
56+
57+
if c.pathSpec.Language != nil {
58+
// Avoid do and store more work than needed. The language versions will in
59+
// most cases be duplicates of the same image files.
60+
key = strings.TrimPrefix(key, "/"+c.pathSpec.Language.Lang)
61+
}
62+
5463
// First check the in-memory store, then the disk.
5564
c.mu.RLock()
5665
img, found := c.store[key]
@@ -68,7 +77,7 @@ func (c *imageCache) getOrCreate(
6877
// but the count of processed image variations for this site.
6978
c.pathSpec.ProcessingStats.Incr(&c.pathSpec.ProcessingStats.ProcessedImages)
7079

71-
r, err := spec.NewResourceFromFilename(nil, c.absPublishDir, cacheFilename, key)
80+
r, err := spec.NewResourceFromFilename(nil, c.absPublishDir, cacheFilename, relTargetFilename)
7281
notFound := err != nil && os.IsNotExist(err)
7382
if err != nil && !os.IsNotExist(err) {
7483
return nil, err

0 commit comments

Comments
 (0)