Skip to content

Conversation

merkys7
Copy link
Member

@merkys7 merkys7 commented Jul 28, 2022

Summary

Fixes #382

Relevant technical choices

Remove plugin option for Multisite during uninstall execution

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

@merkys7 merkys7 added [Type] Bug An existing feature is broken Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release labels Jul 28, 2022
@merkys7 merkys7 requested a review from felixarntz July 29, 2022 09:32
@mxbclang mxbclang removed the no milestone PRs that do not have a defined milestone for release label Jul 29, 2022
@mxbclang mxbclang added this to the 1.4.0 milestone Jul 29, 2022
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a 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.

@merkys7 merkys7 force-pushed the fix/382-remove-plugin-option-for-multisite branch from e0ad3d8 to f315074 Compare August 1, 2022 20:34
@merkys7 merkys7 requested a review from mukeshpanchal27 August 1, 2022 20:40
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a 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() {
Copy link
Member

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

Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

@adamsilverstein adamsilverstein left a 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

@merkys7 merkys7 force-pushed the fix/382-remove-plugin-option-for-multisite branch from f315074 to 6fcc9c6 Compare August 5, 2022 16:29
@merkys7
Copy link
Member Author

merkys7 commented Aug 5, 2022

I really appreciate your feedback @mukeshpanchal27 @adamsilverstein :bowtie: thank you for taking the time.
I have adjusted the PR based on the comments

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a 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 ) ) ) {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Suggested change
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() ) {

Copy link
Member

@felixarntz felixarntz left a 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 ) ) ) {
Copy link
Member

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
Comment on lines 30 to 42
} else {
delete_option( 'perflab_modules_settings' );
}
Copy link
Member

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:

Suggested change
} 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 ) ) ) {
Copy link
Member

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.

Suggested change
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() ) {

@merkys7 merkys7 force-pushed the fix/382-remove-plugin-option-for-multisite branch from 6fcc9c6 to 1d7486b Compare August 8, 2022 17:33
@merkys7
Copy link
Member Author

merkys7 commented Aug 8, 2022

Thank you for the feedback guys :bowtie: I have improved the PR based on the comments

@merkys7 merkys7 force-pushed the fix/382-remove-plugin-option-for-multisite branch from 1d7486b to 5aae8ad Compare August 9, 2022 07:39
Copy link
Member

@felixarntz felixarntz left a 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.

Copy link
Member

@felixarntz felixarntz left a 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 felixarntz merged commit 204479f into trunk Aug 10, 2022
@felixarntz felixarntz deleted the fix/382-remove-plugin-option-for-multisite branch August 10, 2022 14:19
@felixarntz felixarntz changed the title Remove plugin option for Multisite during uninstall Remove plugin option network-wide for Multisite during uninstall Aug 10, 2022
@merkys7
Copy link
Member Author

merkys7 commented Aug 11, 2022

@felixarntz Thank you for the help and feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall performance plugin infrastructure [Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove plugin option for Multisite
5 participants