-
Notifications
You must be signed in to change notification settings - Fork 898
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
Avoid storing the full user object in notifications meta #20800
Avoid storing the full user object in notifications meta #20800
Conversation
* Store only the user ID in the db. * Fix unit tests to take into account accessing the ID attribute of the WP_User object.
The routine will unset the 'user' field in yoast_notifications user meta and add a new 'user_id' field with the user ID.
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.
CR 🏗️
foreach ( $notifications as $notification ) { | ||
$notification_has_been_updated = $notification->user_to_user_id(); | ||
// Just one notification changed is enough to update the storage. | ||
if ( $notification_has_been_updated ) { | ||
$this->notifications_need_storage = true; | ||
} | ||
} | ||
|
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.
I detected an order problem. In filter_notification_current_user
the user_id
is already expected to be there.
But here you convert it only after the filter.
I was thinking of a solution:
- Move the whole loop above the filter
- Move the convert code into the
array_to_notification
method
But then I thought: why not check in the constructor of the notification? Specifically the normalize_options
already has some logic that looks like a spot at first sight?
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.
I think I reached a good middle point:
- Moved the convert code in the
array_to_notification
method - No need to loop anymore becuse of the
array_map
callingarray_to notification
- No need to add the ugly public method in
Yoast_Notification
🙂
By doing so we can still set the notifications_need_storage
flag and save to db the new user_id asap
* | ||
* @return WP_User The user to show this notification for. | ||
* @return int The user id. | ||
*/ | ||
public function get_user() { |
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.
Changing the return value and type is a BC break. I think this is actually just a helper for the method below.
Probably we can just deprecate it?
But perhaps it is wise to not alter it and retrieve the user after getting the ID instead (similar to your has_capability
change)? For BC sake.
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.
I deprecated it, it wouldn't make sense anymore after this PR gets merged 🙂
@@ -841,13 +841,15 @@ public function test_add_notifications_only_once_for_user() { | |||
|
|||
$instance = $this->get_notification_center(); | |||
|
|||
$user_mock = $this->mock_wp_user( 3, [ 'wpseo_manage_options' => true ] ); | |||
$user_id = $this->factory->user->create(); |
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.
I think there is a create_and_get
you can use. If you chose to apply, please also do so in the other tests 😉
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.
Done 👍
Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com>
Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com>
Instead of introducing a breaking change by changing the return type of get_user, we deprecate it as it was only used here.
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.
CR + ACC 👍 Looks good after the changes :)
Context
WP_User
object in each user's notification.Summary
This PR can be summarized in the following changelog entry:
wp_yoast_notifications
usermeta the fullWP_User
object.Relevant technical choices:
Notification_Center::maybe_unset_notification_user_field
method. This is going to be less impactful for sites with a large number of users with respect to using an upgrade routine.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Without this PR checked out
Yoast SEO
->General
->Dashboard
tabProblems
andNotifications
section) you have there and their state (visible or hidden)Yoast Test
helper toReset indexable tables&migrations
: this would trigger a notification about the need to run the SEO data optimizationwp_usermeta
table, and look for the row whereUser Id
= your user id,meta_key
=wp_yoast_notifications
Meta value
forWP_User
and verify you have one instance per notificationSEO Manager
role and repeat the points above for this userWith this PR checked out
Yoast SEO
->General
->Dashboard
tabwp_usermeta
table, and look for the row whereUser Id
= your user id,meta_key
=wp_yoast_notifications
Meta value
forWP_User
and verify you have no instances in any of the notificationsUser Id
= your other user id,meta_key
=wp_yoast_notifications
Meta value
forWP_User
and verify you still have one instance per notificationRelevant test scenarios
Test instructions for QA when the code is in the RC
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Other environments
[shopify-seo]
, added test instructions for Shopify and attached theShopify
label to this PR.Documentation
Quality assurance
Innovation
innovation
label.Fixes #20796