-
Notifications
You must be signed in to change notification settings - Fork 132
Remove plugin option network-wide for Multisite during uninstall #458
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
Conversation
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.
@merkys7 Left some feedback.
e0ad3d8
to
f315074
Compare
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.
@merkys7 Thanks for the updates. The approach here now looks good, Left some more feedback.
uninstall.php
Outdated
* | ||
* @since n.e.x.t | ||
*/ | ||
function delete_data() { |
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.
As per the plugin function name we should use the perflab_
prefix in name of the function. Something like perflab_delete_option
or perflab_delete_plugin_option
.
cc. @felixarntz
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.
do we really need a helper function for one line of code?
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.
In my initial approach, I don't use a helper function for a single line: #345 (comment) But I think it was used two times, so Merkys introduced a helper function. If it doesn't make sense, then can we remove it?
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.
Thank you for the feedback, removed it
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.
Not a blocker, but I also prefer to have a function for this. Yes, it's one line, but IMO it makes sense even to have a function for this to clarify that this needs to be exactly the same logic for a single site as well as for every site in a multisite. Plus it avoids a (admittedly tiny) chance of e.g. a typo in the option name in one of the calls, which in a function call would immediately be flagged as fatal error, but in a string isn't.
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.
left some questions/feedback
f315074
to
6fcc9c6
Compare
I really appreciate your feedback @mukeshpanchal27 @adamsilverstein |
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.
@merkys7 Thanks for the updates. It looks good. I left some final feedback.
uninstall.php
Outdated
@@ -11,4 +11,22 @@ | |||
exit; | |||
} | |||
|
|||
delete_option( 'perflab_modules_settings' ); | |||
if ( is_multisite() && 100 >= get_sites( array( 'count' => 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 feel like we should check the count condition inside the loop. Otherwise, it will run else part for multisite with more than 100 sites.
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 would argue we don't need that check for the site count here at all. It's another query to run, which we can avoid. I think we should still handle multisites in the right way, and we can just limit the get_sites()
query like you do below. That means:
- For networks with 100 or fewer sites, it will wipe all sites.
- For networks with more than 100 sites, it will at least wipe 100 sites.
The latter is not great, but better than what we currently have, while accounting for scalability issues. Also, deleting the option for 100 sites when there are more is still better than falling back to only deleting the option for the current site.
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.
Also, let's add a comment here explaining this block.
if ( is_multisite() && 100 >= get_sites( array( 'count' => true ) ) ) { | |
// For a multisite, delete the option for all sites (however limited to 100 sites to avoid memory limit or timeout problems in large scale networks). | |
if ( is_multisite() ) { |
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.
@merkys7 Thank you for the PR! Left some comments with additional suggestions.
uninstall.php
Outdated
@@ -11,4 +11,22 @@ | |||
exit; | |||
} | |||
|
|||
delete_option( 'perflab_modules_settings' ); | |||
if ( is_multisite() && 100 >= get_sites( array( 'count' => 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 would argue we don't need that check for the site count here at all. It's another query to run, which we can avoid. I think we should still handle multisites in the right way, and we can just limit the get_sites()
query like you do below. That means:
- For networks with 100 or fewer sites, it will wipe all sites.
- For networks with more than 100 sites, it will at least wipe 100 sites.
The latter is not great, but better than what we currently have, while accounting for scalability issues. Also, deleting the option for 100 sites when there are more is still better than falling back to only deleting the option for the current site.
uninstall.php
Outdated
} else { | ||
delete_option( 'perflab_modules_settings' ); | ||
} |
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 it would be best to not have this in an else
, but instead always run it. IMO it makes sense to at least always wipe the current site's (main site) option on uninstall. If a multisite has more than 100 sites, we should still ensure the main site's option is deleted.
So I would suggest the following:
} else { | |
delete_option( 'perflab_modules_settings' ); | |
} | |
} | |
// Delete the current site's option. | |
delete_option( 'perflab_modules_settings' ); |
uninstall.php
Outdated
@@ -11,4 +11,22 @@ | |||
exit; | |||
} | |||
|
|||
delete_option( 'perflab_modules_settings' ); | |||
if ( is_multisite() && 100 >= get_sites( array( 'count' => 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.
Also, let's add a comment here explaining this block.
if ( is_multisite() && 100 >= get_sites( array( 'count' => true ) ) ) { | |
// For a multisite, delete the option for all sites (however limited to 100 sites to avoid memory limit or timeout problems in large scale networks). | |
if ( is_multisite() ) { |
6fcc9c6
to
1d7486b
Compare
Thank you for the feedback guys |
1d7486b
to
5aae8ad
Compare
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.
@merkys7 Thank you for the updates, looks great now! I found one more issue that needs to be addressed.
Small aside: Please avoid force-pushing. Preferably you would simply add commits with your changes to this PR. Otherwise it messes up the git history.
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.
@merkys7 Made the final mini updates here, so this is good to go into 1.4.0 now. Thanks again!
@felixarntz Thank you for the help and feedback! |
Summary
Fixes #382
Relevant technical choices
Remove plugin option for Multisite during uninstall execution
Checklist
[Focus]
orInfrastructure
label.[Type]
label.no milestone
label.