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

fix(profile): Avoid updating the config at each call #45407

Closed
wants to merge 1 commit into from

Conversation

solracsf
Copy link
Member

@solracsf solracsf commented May 20, 2024

Summary

Updating the config at each call can be inefficient. Instead, check if the merged configuration is different from the existing one before performing the update. This optimization may reduce unnecessary database operations.

Checklist

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf solracsf added the 3. to review Waiting for reviews label May 20, 2024
@solracsf solracsf added this to the Nextcloud 30 milestone May 20, 2024
@solracsf solracsf added performance 🚀 feature: profile PRs or issues related to the Profile feature (e.g. Profile page, API, etc.) labels May 20, 2024
@solracsf solracsf self-assigned this May 21, 2024
$mergedConfigArray = array_merge($defaultProfileConfig, $existingConfigArray);

// Only update if the merged config is different from the existing config
if ($mergedConfigArray !== $existingConfigArray) {
Copy link
Member

Choose a reason for hiding this comment

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

had to check if php considers two array identical but seems to be the case 👍 https://3v4l.org/oGKFE

Comment on lines -345 to -349
$config->setConfigArray(array_merge(
$defaultProfileConfig,
$this->filterNotStoredProfileConfig($config->getConfigArray()),
));
$this->configMapper->update($config);
Copy link
Member

Choose a reason for hiding this comment

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

The magic setter of an entity should already skip assignments when the value does not change:

if ($args[0] === $this->$name) {
return;
}
. The mapper skips the UPDATE query if there are no updated fields:
$properties = $entity->getUpdatedFields();
if (\count($properties) === 0) {
return $entity;
}
.

Hence I wonder if the UPDATE is actually run before your changes. And if so, why. Possible causes

  1. The arrays are not identical, or the json representation isnt.
  2. Other fields of the config are assigned.

Could you check?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, in our case one extension was causing fields updates on the fly. Disabling it fixed those chatty DB queries.
So closing this, as the server behaves as it should 👍

@solracsf solracsf closed this May 23, 2024
@solracsf solracsf deleted the updateConfigIfNeeded branch May 23, 2024 08:17
@solracsf solracsf removed 3. to review Waiting for reviews performance 🚀 feature: profile PRs or issues related to the Profile feature (e.g. Profile page, API, etc.) labels May 23, 2024
Copy link

github-actions bot commented Jun 4, 2024

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants