Skip to content

Purge npm store when the disk is low#1329

Merged
ije merged 9 commits intomainfrom
disk
Mar 13, 2026
Merged

Purge npm store when the disk is low#1329
ije merged 9 commits intomainfrom
disk

Conversation

@ije
Copy link
Member

@ije ije commented Mar 12, 2026

No description provided.

ije added 2 commits March 13, 2026 07:52
- 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.
Copilot AI review requested due to automatic review settings March 12, 2026 23:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 esmRouter to purge the npm store when disk status is low.
  • Extract disk-space checking and npm cache purging into a new server/disk.go helper.
  • 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.

Comment on lines +420 to +428
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
}
Comment on lines +424 to +427
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
Comment on lines +82 to +92
// 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)
}
}
}()

ije and others added 3 commits March 13, 2026 08:00
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 esmRouter to purge the npm store when disk space is low/full.
  • Introduce server/disk.go with checkDiskStatus() and purgeNPMCacheWhenDiskIsLowOrFull().
  • 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.

Comment on lines +420 to +428
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
}
ije and others added 4 commits March 13, 2026 08:19
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@ije ije merged commit 7b75679 into main Mar 13, 2026
8 of 10 checks passed
@ije ije deleted the disk branch March 13, 2026 01:15
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