summaryrefslogtreecommitdiffstats
path: root/resource
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-07 11:29:02 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-07 11:58:16 +0100
commit4b04db0f0855a1f54895d6c93c52dcea4b1ce3ca (patch)
tree48140bbdb62ec15202fcf94a3d1ef691c5a78746 /resource
parent97c1866e322284dec46db6f3d235807507f5b69f (diff)
resource: Avoid processing and storing same image for each language
Fixes #4231
Diffstat (limited to 'resource')
-rw-r--r--resource/image.go2
-rw-r--r--resource/image_cache.go11
2 files changed, 11 insertions, 2 deletions
diff --git a/resource/image.go b/resource/image.go
index 8a65be1bf..678a78ad7 100644
--- a/resource/image.go
+++ b/resource/image.go
@@ -219,7 +219,7 @@ func (i *Image) doWithImageConfig(action, spec string, f func(src image.Image, c
}
if conf.Rotate != 0 {
- // Rotate it befor any scaling to get the dimensions correct.
+ // Rotate it before any scaling to get the dimensions correct.
src = imaging.Rotate(src, float64(conf.Rotate), color.Transparent)
}
diff --git a/resource/image_cache.go b/resource/image_cache.go
index 14350986e..c2d5d0ad5 100644
--- a/resource/image_cache.go
+++ b/resource/image_cache.go
@@ -51,6 +51,15 @@ func (c *imageCache) deleteByPrefix(prefix string) {
func (c *imageCache) getOrCreate(
spec *Spec, key string, create func(resourceCacheFilename string) (*Image, error)) (*Image, error) {
+
+ relTargetFilename := key
+
+ if c.pathSpec.Language != nil {
+ // Avoid do and store more work than needed. The language versions will in
+ // most cases be duplicates of the same image files.
+ key = strings.TrimPrefix(key, "/"+c.pathSpec.Language.Lang)
+ }
+
// First check the in-memory store, then the disk.
c.mu.RLock()
img, found := c.store[key]
@@ -68,7 +77,7 @@ func (c *imageCache) getOrCreate(
// but the count of processed image variations for this site.
c.pathSpec.ProcessingStats.Incr(&c.pathSpec.ProcessingStats.ProcessedImages)
- r, err := spec.NewResourceFromFilename(nil, c.absPublishDir, cacheFilename, key)
+ r, err := spec.NewResourceFromFilename(nil, c.absPublishDir, cacheFilename, relTargetFilename)
notFound := err != nil && os.IsNotExist(err)
if err != nil && !os.IsNotExist(err) {
return nil, err