ref: 0024dcfe3e016c67046de06d1dac5e7f5235f9e1
parent: beec1fc98e5d37bba742d6bc2a0ff7c344b469f8
author: Bjørn Erik Pedersen <[email protected]>
date: Thu Jul 12 14:59:39 EDT 2018
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.
--- a/resource/transform.go
+++ b/resource/transform.go
@@ -303,12 +303,6 @@
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 @@
r.cache.nlocker.Unlock(key)
return
}
+
defer r.cache.nlocker.Unlock(key)
defer r.cache.set(key, r)
@@ -362,6 +357,13 @@
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