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.
This commit is contained in:
Bjørn Erik Pedersen 2018-07-12 18:59:39 +02:00
parent beec1fc98e
commit 0024dcfe3e

View file

@ -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