mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 02:32:11 -05:00
resource: Avoid processing and storing same image for each language
Fixes #4231
This commit is contained in:
parent
97c1866e32
commit
4b04db0f08
2 changed files with 11 additions and 2 deletions
|
@ -219,7 +219,7 @@ func (i *Image) doWithImageConfig(action, spec string, f func(src image.Image, c
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.Rotate != 0 {
|
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)
|
src = imaging.Rotate(src, float64(conf.Rotate), color.Transparent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,15 @@ func (c *imageCache) deleteByPrefix(prefix string) {
|
||||||
|
|
||||||
func (c *imageCache) getOrCreate(
|
func (c *imageCache) getOrCreate(
|
||||||
spec *Spec, key string, create func(resourceCacheFilename string) (*Image, error)) (*Image, error) {
|
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.
|
// First check the in-memory store, then the disk.
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
img, found := c.store[key]
|
img, found := c.store[key]
|
||||||
|
@ -68,7 +77,7 @@ func (c *imageCache) getOrCreate(
|
||||||
// but the count of processed image variations for this site.
|
// but the count of processed image variations for this site.
|
||||||
c.pathSpec.ProcessingStats.Incr(&c.pathSpec.ProcessingStats.ProcessedImages)
|
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)
|
notFound := err != nil && os.IsNotExist(err)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue