perf(pages): stream asset files instead of buffering in memory
Some checks failed
Build and Release / Create Release (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m52s
Build and Release / Unit Tests (push) Successful in 9m0s
Build and Release / Lint (push) Successful in 9m31s
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Successful in 4m47s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Successful in 9h5m7s
Build and Release / Build Binaries (amd64, darwin, macos) (push) Failing after 0s
Build and Release / Build Binaries (arm64, darwin, macos) (push) Failing after 3s
Build and Release / Build Binary (linux/arm64) (push) Failing after 11m19s
Some checks failed
Build and Release / Create Release (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m52s
Build and Release / Unit Tests (push) Successful in 9m0s
Build and Release / Lint (push) Successful in 9m31s
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Successful in 4m47s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Successful in 9h5m7s
Build and Release / Build Binaries (amd64, darwin, macos) (push) Failing after 0s
Build and Release / Build Binaries (arm64, darwin, macos) (push) Failing after 3s
Build and Release / Build Binary (linux/arm64) (push) Failing after 11m19s
Replace full-file buffering with io.Copy streaming in serveRepoFileAsset. Reduces memory usage for large assets (images, videos) by streaming directly from git blob to HTTP response. Adds Content-Length header for better client handling.
This commit is contained in:
@@ -843,15 +843,9 @@ func serveRepoFileAsset(ctx *context.Context, commit *git.Commit, assetPath stri
|
||||
ctx.Resp.Header().Set("Content-Type", contentType)
|
||||
ctx.Resp.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
|
||||
// Stream content
|
||||
content := make([]byte, entry.Blob().Size())
|
||||
_, err = reader.Read(content)
|
||||
if err != nil && err.Error() != "EOF" {
|
||||
ctx.ServerError("Failed to read asset", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = ctx.Resp.Write(content)
|
||||
// Stream content directly to the response
|
||||
ctx.Resp.Header().Set("Content-Length", strconv.FormatInt(entry.Blob().Size(), 10))
|
||||
_, _ = io.Copy(ctx.Resp, reader)
|
||||
}
|
||||
|
||||
// servePageEvent handles POST /pages/events for A/B test event tracking
|
||||
|
||||
Reference in New Issue
Block a user