diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-07-12 18:59:39 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-07-12 19:36:12 +0200 |
commit | 0024dcfe3e016c67046de06d1dac5e7f5235f9e1 (patch) | |
tree | 4ad43dfa8d7435c5b8f85ac7653378c0cdd44aef /resource | |
parent | beec1fc98e5d37bba742d6bc2a0ff7c344b469f8 (diff) | |
download | hugo-0024dcfe3e016c67046de06d1dac5e7f5235f9e1.tar.gz hugo-0024dcfe3e016c67046de06d1dac5e7f5235f9e1.zip |
resource: Move opening of the transformed resources after cache check
The old version should be functionally the same, but opening up these readers (potentially files) every time is wasteful if we don't read from them.
Diffstat (limited to 'resource')
-rw-r--r-- | resource/transform.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/resource/transform.go b/resource/transform.go index 005ede767..93ace2ba0 100644 --- a/resource/transform.go +++ b/resource/transform.go @@ -303,12 +303,6 @@ func (r *transformedResource) transform(setContent bool) (err error) { first := chain[0] - contentrc, err := contentReadSeekerCloser(first) - if err != nil { - return err - } - defer contentrc.Close() - // Files with a suffix will be stored in cache (both on disk and in memory) // partitioned by their suffix. There will be other files below /other. // This partition is also how we determine what to delete on server reloads. @@ -347,6 +341,7 @@ func (r *transformedResource) transform(setContent bool) (err error) { r.cache.nlocker.Unlock(key) return } + defer r.cache.nlocker.Unlock(key) defer r.cache.set(key, r) @@ -362,6 +357,13 @@ func (r *transformedResource) transform(setContent bool) (err error) { tctx.InMediaType = first.MediaType() tctx.OutMediaType = first.MediaType() + + contentrc, err := contentReadSeekerCloser(first) + if err != nil { + return err + } + defer contentrc.Close() + tctx.From = contentrc tctx.To = b1 |