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

Eliminate redundant Model::save() calls in nested mutations #2570

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

spawnia
Copy link
Collaborator

@spawnia spawnia commented Jun 14, 2024

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md

Changes

Because NestedBelongsTo unnecessarily passed through the $parentRelation to SaveModel, updating multiple BelongsTo relations of a model in a single nested mutation resulted in multiple save operations. See the repeated calls to update `users` set in the following log:

"select * from `users` where `users`.`id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `companies` where `companies`.`id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `companies` set `name` = ?, `companies`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `users` set `name` = ?, `company_id` = ?, `users`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `teams` where `teams`.`id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `teams` set `name` = ?, `teams`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `users` set `team_id` = ?, `users`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `users` where `id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `companies` where `companies`.`id` in (1)" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `teams` where `teams`.`id` in (1)" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518

Failed asserting that actual size 2 matches expected size 1.
/workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:570

Breaking changes

Should be none.

@spawnia spawnia added the bug An error within Lighthouse label Jun 17, 2024
@spawnia spawnia merged commit ea496a2 into master Jun 17, 2024
41 checks passed
@spawnia spawnia deleted the remove-redundant-nested-mutations-save branch June 17, 2024 08:59
spawnia added a commit that referenced this pull request Jun 17, 2024
Comment on lines 30 to 32
if ($args->has('update')) {
$updateModel = new ResolveNested(new UpdateModel(new SaveModel($relation)));
$updateModel = new ResolveNested(new UpdateModel(new SaveModel()));

Copy link
Contributor

Choose a reason for hiding this comment

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

#2590 this line broke my specific use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error within Lighthouse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants