Skip to content

Commit

Permalink
prefetch placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Mar 9, 2018
1 parent 271c5d7 commit 6accc4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 9 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"sync"

"github.com/aldor007/mort/pkg/helpers"
"github.com/aldor007/mort/pkg/monitoring"
)

Expand Down Expand Up @@ -241,6 +242,14 @@ func (c *Config) validateServer() error {
c.Server.QueueLen = 5
}

if c.Server.Placeholder != "" {
var err error
c.Server.PlaceholderBuf, err = helpers.FetchObject(c.Server.Placeholder)
if err != nil {
return err
}
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@ type Server struct {
Listen []string `yaml:"listens"`
Monitoring string `yaml:"monitoring"`
Placeholder string `yaml:"placeholder"`
PlaceholderBuf []byte
}
11 changes: 3 additions & 8 deletions pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/aldor007/mort/pkg/config"
"github.com/aldor007/mort/pkg/engine"
"github.com/aldor007/mort/pkg/helpers"
"github.com/aldor007/mort/pkg/lock"
"github.com/aldor007/mort/pkg/monitoring"
"github.com/aldor007/mort/pkg/object"
Expand Down Expand Up @@ -96,17 +95,13 @@ func (r *RequestProcessor) replyWithError(obj *object.FileObject, sc int, err er
return response.NewError(sc, err)
}

key := r.serverConfig.Placeholder + strconv.FormatUint(obj.Transforms.Hash().Sum64(), 16) + strconv.FormatInt(int64(sc), 10)
key := r.serverConfig.Placeholder + strconv.FormatUint(obj.Transforms.Hash().Sum64(), 16)
if cacheRes := r.fetchResponseFromCache(key); cacheRes != nil {
cacheRes.StatusCode = sc
return cacheRes
}

buf, err := helpers.FetchObject(r.serverConfig.Placeholder)
if err != nil {
return response.NewError(sc, err)
}

parent := response.NewBuf(sc, buf)
parent := response.NewBuf(sc, r.serverConfig.PlaceholderBuf)
transformsTab := []transforms.Transforms{obj.Transforms}

eng := engine.NewImageEngine(parent)
Expand Down
2 changes: 1 addition & 1 deletion pkg/response/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package response
import (
"bytes"
"errors"
"github.com/aldor007/mort/pkg/object"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/aldor007/mort/pkg/object"
)

func TestResponse_Copy(t *testing.T) {
Expand Down

0 comments on commit 6accc4c

Please sign in to comment.