p5.js-web-editor icon indicating copy to clipboard operation
p5.js-web-editor copied to clipboard

[Draft] Orphaned Assets Fix

Open raclim opened this issue 6 months ago • 3 comments

Background

This PR addresses issues with orphaned assets accumulating in the AWS s3 Bucket. Currently, one confirmed cause can be reproduced by:

  1. Creating a New Project.
  2. Uploading an Asset.
  3. Closing the Project Window/Tab without Saving the Project.
  4. 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 : Reference req.user.id instead of req.body.userId. Adds in the pending folder 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 the pending folder.
  • server/controllers/project.controller.js: Adds the commitPendingAssets util to the project controller and removes the portion checking for stale files. I felt that this wasn't successfully capturing
  • client/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 develop branch.
  • [ ] is descriptively named and links to an issue number, i.e. Fixes #123
  • [ ] meets the standards outlined in the accessibility guidelines

raclim avatar May 05 '26 02:05 raclim

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

release-com[bot] avatar May 05 '26 02:05 release-com[bot]

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?

image

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?

skyyash avatar Jun 09 '26 14:06 skyyash

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).

ksen0 avatar Jun 12 '26 03:06 ksen0