Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

Resolved TODO at pkg/router/files.go:247 to eliminate memory exhaustion on large file uploads. Found and fixed additional performance issues and bugs during code review.

Changes

Streaming upload implementation

  • Replaced io.ReadAll() with streaming via io.TeeReader and io.MultiReader
  • Compute SHA256 checksum on-the-fly while streaming to S3
  • Use bytes.NewReader instead of strings.NewReader(string(body)) to avoid allocation

Regions config caching

  • Load regions configuration once at startup, not on every request
  • Store in router struct at initialization

Bug fixes

  • DecrementHandler: Added early return to prevent double HTTP responses when file is deleted
  • Size limit check: Changed > to >= for correct boundary enforcement
  • S3 deletion failures: Added error logging for oversized file cleanup

Example

Before:

body, err := io.ReadAll(requestFile)  // Entire file in memory
// ... 
Body: strings.NewReader(string(body)),  // Another copy as string

After:

streamReader := io.MultiReader(
    io.TeeReader(bytes.NewReader(firstChunk[:n]), hash),
    io.TeeReader(sizeLimitReader, hash),
)
// Stream directly to S3 while computing checksum
Original prompt

в pkg/router/files.go:247 строке есть TODO, реши его, а так же посмотри по коду может есть еще проблемы с оптимизациями, реши их тоже если найдешь


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 6 commits December 30, 2025 00:29
Co-authored-by: 0xF6 <13326808+0xF6@users.noreply.github.com>
Co-authored-by: 0xF6 <13326808+0xF6@users.noreply.github.com>
Co-authored-by: 0xF6 <13326808+0xF6@users.noreply.github.com>
…ison

Co-authored-by: 0xF6 <13326808+0xF6@users.noreply.github.com>
Co-authored-by: 0xF6 <13326808+0xF6@users.noreply.github.com>
Co-authored-by: 0xF6 <13326808+0xF6@users.noreply.github.com>
@0xF6 0xF6 requested a review from urumo December 30, 2025 00:38
Co-authored-by: 0xF6 <13326808+0xF6@users.noreply.github.com>
Copilot AI changed the title [WIP] Resolve TODO and optimize code in router Optimize file upload with streaming and fix memory/performance issues Dec 30, 2025
Copilot AI requested a review from 0xF6 December 30, 2025 00:39
@0xF6 0xF6 marked this pull request as ready for review December 30, 2025 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants