Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a production tooling script to identify and remove (or quarantine) orphaned objects in the assets.pubpub.org S3 bucket by scanning the Postgres DB for referenced asset keys, comparing against a full bucket listing, and then acting on the orphan set.
Changes:
- Add
tools/s3Cleanup.tsimplementing DB reference collection, S3 listing with resume support, and delete/quarantine/unquarantine flows. - Register the new
s3Cleanupcommand in the tools command router.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tools/s3Cleanup.ts |
New CLI tool for scanning DB references, listing S3 keys, and deleting/quarantining unreferenced objects. |
tools/index.js |
Adds s3Cleanup to the available tools commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
tools/s3Cleanup.ts- a script that identifies and removes unreferenced objects from theassets.pubpub.orgS3 bucket.Problem
Every uploaded asset is retained forever, even after being replaced in-app (all uploads get unique filenames). There's been no mechanism to identify or remove orphaned files.
How it works
Phase 1 — Scan the database for every reference to an
assets.pubpub.orgkey. This covers:Pubs.downloads, layout block banner images, layout HTML blocks, layout text blocks (DocJson), layout submission-banner bodieshtmlTitle/htmlDescription, CommunityheroText, WorkerTaskinput/outputresize-v3(base64),resizev1 (Thumbor),s3-external-1.amazonaws.comPhase 2 — List the S3 bucket and compare each object's key against the referenced set. Writes orphans to
orphans.txt.Phase 3 — Delete orphans in batches of 1,000 (only with
--execute).Safety measures
--min-age-days=N)--execute, only writes a manifest — no deletions--resume_testing/prefix keys are always skippedUsage