Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Google Blockly] strip random block ids when saving xml #56299

Merged
merged 6 commits into from
Feb 13, 2024

Conversation

mikeharv
Copy link
Contributor

@mikeharv mikeharv commented Feb 5, 2024

Recently, there was concern about the potential for storing identical solutions in the level_sources table in DB-backed levels for Google Blockly labs.

@breville said:

The level_sources table is designed to only save one copy of each unique solution. The saves us from writing tons of duplicate entries. However, if each solution has some random IDs in it, we suddenly are saving every copy of what's essentially the same source.

He added:

I think x/y is probably not such a big issue for levels where students are unlikely (or unable) to drag the parent block to a new position. However, if IDs are truly unique for every use, then they seem like a more concerning issue.

Currently, this issue impacts DB-backed levels using Flappy, Bounce, and Dance. As it happens, Sprite Lab/Poetry are never DB-backed, always using S3 for project storage. Minecraft also uses the database for many levels, so it makes sense to address this before migrating that lab.

Stripping block ids at the time of saving is a reasonable step forward, however there are times when blocks need to have explicitly set ids. For example, block ids are used with callouts, automated tests, and possibly some older forms of Blockly code validation.

This branch creates a new property on the Blockly Wrapper that stores a list of block ids that were explicitly set in the level (start blocks or toolbox). Any other ids found can safely be considered randomly generated by Blockly and discarded.

Links

Testing story

To test this change, I solved a Minecraft puzzle the same way twice. I logged the XML before and after the stripping and observed the following:

  • Before stripping, each program contained with completely different ids, except for a when_run block with id whenRun.
  • All random/unique ids were detected and removed.
  • After stripping, each program's XML was identical.

I had to get creative with the way the appOptions.level object was passed and accessed due to failing automated tests. While appOptions is typically available globally, this didn't prove true in the context of some are tests that needed to traverse these code changes.

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@mikeharv
Copy link
Contributor Author

mikeharv commented Feb 5, 2024

This PR is a continuation of #56192, which was mis-closed by the Git LFS migration (#55759).

Previous Comments:

Previous Reviews:

@mikeharv mikeharv requested a review from a team February 5, 2024 17:39
function removeIdsFromBlocks(element) {
if (element.nodeName === 'block') {
const id = element.getAttribute('id');
if (id && !Blockly.levelBlockIds.includes(id)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this function is only used in the context of google blockly right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. And true of everything in this file!

Copy link
Contributor

@molly-moen molly-moen left a comment

Choose a reason for hiding this comment

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

Nice!

@mikeharv
Copy link
Contributor Author

mikeharv commented Feb 5, 2024

I just added one more commit: c9c9475

The sharepage.feature UI test was failing: https://drone.cdn-code.org/code-dot-org/code-dot-org/39546

The reason for this is that loads in some block XML containing block ids which are needed to check the arrangement of the blocks.

https://github.com/code-dot-org/code-dot-org/blob/mike/strip-random-block-ids/dashboard/test/ui/features/step_definitions/flappy_steps.rb#L17-L21

In practice, these blocks would have random ids which are now getting stripped out. To preserve the ids for the test, we can just add them to the toolbox and start blocks XML.

@ebeastlake
Copy link
Contributor

🎉 Should we hold off on merging this until after the Sprite Lab migration?

@mikeharv
Copy link
Contributor Author

mikeharv commented Feb 5, 2024

🎉 Should we hold off on merging this until after the Sprite Lab migration?

@ebeastlake I don't think it matters. We'll only be saving JSON for Sprite Lab (outside of levelbuilder functions), and never writing Sprite Lab solutions to the database.

Edit: Let's hold this until after the migration!

Copy link
Member

@breville breville left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

@breville
Copy link
Member

breville commented Feb 6, 2024

It might be good to check the production database before and after this is merged just to verify that we are indeed saving fewer unique solutions!

@mikeharv
Copy link
Contributor Author

@breville Agreed! That is the plan.

@mikeharv mikeharv merged commit dc71950 into staging Feb 13, 2024
2 checks passed
@mikeharv mikeharv deleted the mike/strip-random-block-ids branch February 13, 2024 13:58
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.

None yet

4 participants