Conversation
- Introduced a new file `disk.go` to handle disk status checks and cache purging. - Implemented `checkDiskStatus` function to assess available disk space and return appropriate status. - Added `purgeNPMCache` function to remove old NPM cache when disk space is low. - Integrated periodic disk status checks in the router to trigger cache purging when necessary.
- Replaced direct checks for `fsCache` and `.mjs.map` suffixes with a new method `shouldUseFSCache`. - Updated `Stat`, `Get`, `Put`, and `Delete` methods to utilize the new cache usage logic for improved readability and maintainability.
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce disk pressure by automatically purging the server’s local npm store when available disk space drops, and it also adjusts which objects are eligible for local filesystem caching in the S3 storage backend.
Changes:
- Add an hourly background task in
esmRouterto purge the npm store when disk status is low. - Extract disk-space checking and npm cache purging into a new
server/disk.gohelper. - Centralize S3 fsCache gating logic via
shouldUseFSCache, expanding the list of suffixes excluded from fsCache.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
server/router.go |
Starts an hourly goroutine to purge npm store when disk is low; refactors /status.json disk reporting to use checkDiskStatus(). |
server/disk.go |
Introduces DiskStatus, checkDiskStatus(), and purgeNPMCache() helpers. |
internal/storage/storage_s3.go |
Replaces repeated fsCache checks with shouldUseFSCache() and expands excluded suffixes (e.g., .d.ts). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (s3 *s3Storage) shouldUseFSCache(name string) bool { | ||
| if s3.fsCache == nil { | ||
| return false | ||
| } | ||
| if strings.HasSuffix(name, ".mjs.map") || strings.HasSuffix(name, ".d.ts") || strings.HasSuffix(name, ".d.mts") || strings.HasSuffix(name, ".d.cts") { | ||
| return false | ||
| } | ||
| return true | ||
| } |
| if strings.HasSuffix(name, ".mjs.map") || strings.HasSuffix(name, ".d.ts") || strings.HasSuffix(name, ".d.mts") || strings.HasSuffix(name, ".d.cts") { | ||
| return false | ||
| } | ||
| return true |
server/router.go
Outdated
| // purge npm cache when disk is low | ||
| go func() { | ||
| ticker := time.NewTicker(1 * time.Hour) | ||
| defer ticker.Stop() | ||
| for range ticker.C { | ||
| if checkDiskStatus() == DiskStatusLow { | ||
| purgeNPMCache(npmrc) | ||
| } | ||
| } | ||
| }() | ||
|
|
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds automatic disk-space mitigation by periodically purging the server’s local npm store when free space is low/full, and centralizes disk status checks for the /status.json endpoint. Also refactors S3 FS-cache eligibility into a helper and expands the set of file types excluded from FS caching.
Changes:
- Start a background hourly ticker in
esmRouterto purge the npm store when disk space is low/full. - Introduce
server/disk.gowithcheckDiskStatus()andpurgeNPMCacheWhenDiskIsLowOrFull(). - Factor S3 FS-cache gating into
shouldUseFSCache()and exclude additional suffixes from caching.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
server/router.go |
Starts periodic npm-store purge and uses centralized disk-status check for /status.json. |
server/disk.go |
Implements disk status detection and npm-store purge logic. |
internal/storage/storage_s3.go |
Adds shouldUseFSCache() helper and broadens FS-cache exclusions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (s3 *s3Storage) shouldUseFSCache(name string) bool { | ||
| if s3.fsCache == nil { | ||
| return false | ||
| } | ||
| if strings.HasSuffix(name, ".mjs.map") || strings.HasSuffix(name, ".d.ts") || strings.HasSuffix(name, ".d.mts") || strings.HasSuffix(name, ".d.cts") { | ||
| return false | ||
| } | ||
| return true | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
No description provided.