-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
$mergedConfigArray = array_merge($defaultProfileConfig, $existingConfigArray); | ||
|
||
// Only update if the merged config is different from the existing config | ||
if ($mergedConfigArray !== $existingConfigArray) { |
There was a problem hiding this comment.
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
$config->setConfigArray(array_merge( | ||
$defaultProfileConfig, | ||
$this->filterNotStoredProfileConfig($config->getConfigArray()), | ||
)); | ||
$this->configMapper->update($config); |
There was a problem hiding this comment.
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:
server/lib/public/AppFramework/Db/Entity.php
Lines 108 to 110 in 474cbda
if ($args[0] === $this->$name) { | |
return; | |
} |
server/lib/public/AppFramework/Db/QBMapper.php
Lines 184 to 187 in 474cbda
$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
- The arrays are not identical, or the json representation isnt.
- Other fields of the config are assigned.
Could you check?
There was a problem hiding this comment.
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 👍
Hello there, 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.) |
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