Skip to content

Commit

Permalink
replace strings buffer with hasher (ollama#2437)
Browse files Browse the repository at this point in the history
the buffered value is going into the hasher eventually so write directly
to the hasher instead
  • Loading branch information
mxyng authored Feb 21, 2024
1 parent 949d7b1 commit 210b652
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions server/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"net/http"
"net/url"
"os"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -177,16 +176,14 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) {
requestURL := <-b.nextURL

// calculate md5 checksum and add it to the commit request
var sb strings.Builder
md5sum := md5.New()
for _, part := range b.Parts {
sb.Write(part.Sum(nil))
md5sum.Write(part.Sum(nil))
}

md5sum := md5.Sum([]byte(sb.String()))

values := requestURL.Query()
values.Add("digest", b.Digest)
values.Add("etag", fmt.Sprintf("%x-%d", md5sum, len(b.Parts)))
values.Add("etag", fmt.Sprintf("%x-%d", md5sum.Sum(nil), len(b.Parts)))
requestURL.RawQuery = values.Encode()

headers := make(http.Header)
Expand Down

0 comments on commit 210b652

Please sign in to comment.