optimize: select and update necessary fields in ChangePassword
method
#2058
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ChangePassword
method signature by removing unnecessary return type.Select()
to fetch only the necessary fields (id
andpassword
) from the database.Save()
withUpdate()
for more efficient password update operation.Note: use
Save(&user)
to update the whole user record, which will cover other unchanged fields as well, causing data inconsistency when data race conditions.使用 update 替换 save,同时只更新要更新的字段,避免数据竞争时全覆盖造成数据错误。