fix: serveFromStore does a guaranteed-miss S3 lookup on every cache hit (#82)
Fixes #78 ## Why `serveFromStore` first called `store.Download` with the bare content hash as the S3 key, which never matches real object keys (`blobs/sha256/<hash>`). Every cached blob serve therefore paid an extra guaranteed-404 round-trip before retrying with the correct `BlobKey`. ## Changes - Remove the dead first `Download` attempt; go straight to the `BlobKey` lookup, then fall back to the index key. ## Validation - `make e2e` passes (proxy cache-hit paths exercised end-to-end). Reviewed-on: #82 Co-authored-by: Ben Vincent <ben@unkin.net> Co-committed-by: Ben Vincent <ben@unkin.net>
This commit was merged in pull request #82.
This commit is contained in:
@@ -250,17 +250,8 @@ func (e *Engine) fetchFromUpstream(ctx context.Context, remote models.Remote, pa
|
|||||||
func (e *Engine) serveFromStore(ctx context.Context, remote models.Remote, path string) (*FetchResult, error) {
|
func (e *Engine) serveFromStore(ctx context.Context, remote models.Remote, path string) (*FetchResult, error) {
|
||||||
artifact, err := e.db.GetArtifact(ctx, remote.Name, path)
|
artifact, err := e.db.GetArtifact(ctx, remote.Name, path)
|
||||||
if err == nil && artifact != nil {
|
if err == nil && artifact != nil {
|
||||||
reader, info, err := e.store.Download(ctx, artifact.ContentHash[len("sha256:"):])
|
|
||||||
if err == nil {
|
|
||||||
_ = e.db.TouchArtifactAccess(ctx, remote.Name, path)
|
|
||||||
return &FetchResult{
|
|
||||||
Reader: reader,
|
|
||||||
ContentType: info.ContentType,
|
|
||||||
Size: info.Size,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
s3Key := storage.BlobKey(artifact.ContentHash[len("sha256:"):])
|
s3Key := storage.BlobKey(artifact.ContentHash[len("sha256:"):])
|
||||||
reader, info, err = e.store.Download(ctx, s3Key)
|
reader, info, err := e.store.Download(ctx, s3Key)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = e.db.TouchArtifactAccess(ctx, remote.Name, path)
|
_ = e.db.TouchArtifactAccess(ctx, remote.Name, path)
|
||||||
return &FetchResult{
|
return &FetchResult{
|
||||||
|
|||||||
Reference in New Issue
Block a user