[Draft] Orphaned Assets Fix
Background
This PR addresses issues with orphaned assets accumulating in the AWS s3 Bucket. Currently, one confirmed cause can be reproduced by:
- Creating a New Project.
- Uploading an Asset.
- Closing the Project Window/Tab without Saving the Project.
- Comparing the listed assets within the database vs. the s3 bucket. The asset uploaded to the unsaved project will be visible in AWS, but the project will not exist in the database.
Another potential cause is when project cloning is disrupted, since it appears that assets are uploaded to s3 before the project is successfully cloned.
Changes:
This PR proposes creating a pending folder within the S3 bucket that will hold uploaded user assets until a user saves their project. On project save, the asset should be removed from the pending folder and be moved to the general bucket. This PR is incomplete, and currently conflicts with other scenarios, such as when a user uploads assets to a saved project.
This solution altogether is also just a suggestion, so I'm definitely open to other ideas on this as well!
aws.controller.js: Referencereq.user.idinstead ofreq.body.userId. Adds in thependingfolder when a user uploads an asset.server/utils/pendingAssets.js: Adds a util that handles committing any pending assets to the general bucket on project save, which should copy the asset and delete it from thependingfolder.server/controllers/project.controller.js: Adds thecommitPendingAssetsutil to the project controller and removes the portion checking for stale files. I felt that this wasn't successfully capturingclient/modules/IDE/actions/project.js: When a user attempts to clone a project, it will now delete any added s3 files if the project cloning fails.
I have verified that this pull request:
- [ ] has no linting errors (
npm run lint) - [ ] has no test errors (
npm run test) - [ ] has no typecheck errors (
npm run typecheck) - [ ] is from a uniquely-named feature branch and is up to date with the
developbranch. - [ ] is descriptively named and links to an issue number, i.e.
Fixes #123 - [ ] meets the standards outlined in the accessibility guidelines
Release Environments
This Environment is provided by Release, learn more! To see the status of the Environment click on Environment Status below.
:wrench:Environment Status : https://app.release.com/public/Processing%20Foundation/env-58239eb320
hi @raclim!
i was reviewing the PRs around this and realized: why are we allowing asset uploads before a project is saved in the first place?
it seems like both this and #4085 originate from that behavior. if a project doesn't exist yet, could we simply prompt the user to save/create the project before allowing uploads?
i might be missing an important use case here, but at first glance that feels simpler than introducing a pending-assets workflow in S3 and handling all the edge cases around moving assets between pending and committed states.
is there a reason we need to support uploads to unsaved projects?
Great question, thanks for flagging @skyash-dev . We ended up having a longer discussion about the intent for the current flow (@catarak @raclim and me). The original intent was in line with the core goal of the editor: to make the it possible to make quick sketches without saving; including sketches with assets. (We noted that UX around saving has also changed since original implementation.) So I think keeping the approach of temporary storage enables this (linking open PRs: https://github.com/processing/p5.js-web-editor/pull/4162, https://github.com/processing/p5.js-web-editor/pull/4161, https://github.com/processing/p5.js-web-editor/pull/4119).