Skip to content

Implement mechanism to not load module if core version is available #390

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

Merged
merged 29 commits into from
Jul 8, 2022

Conversation

mukeshpanchal27
Copy link
Member

Summary

This PR works when function wp_image_use_alternate_mime_types() (see WordPress core PR WordPress/wordpress-develop#2393) implemented in WordPress core.

How to test PR in WordPress 6.0

If you want to test PR then please pull from the git change this line code.

if ( function_exists( 'wp_image_use_alternate_mime_types' ) ) {

Replace it with wp_recursive_ksort() which introduce in WordPress 6.0.

if ( function_exists( 'wp_recursive_ksort' ) ) {

If you want to test can-load.php for the other module then please copy the file from the webp-uploads module and paste it into the other modules.

For testing purposes, I have created a can-load.php file for dominant-color and persistent-object-cache-health-check modules.

Fixes #293

Checklist

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

@mukeshpanchal27 mukeshpanchal27 added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall performance plugin infrastructure labels Jun 22, 2022
@mukeshpanchal27 mukeshpanchal27 added the no milestone PRs that do not have a defined milestone for release label Jun 22, 2022
Copy link
Contributor

@jjgrainger jjgrainger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me based on our discussions previously, just a few spelling fixes I noticed.

Co-authored-by: Crisoforo Gaspar Hernández <hello@crisoforo.com>
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.

@mukeshpanchal27 This is mostly looking good so far, however the API approach you're taking here is different from the issue, so I'm curious why you decided to divert from that - IMO it's more complicated than needed.

That's my main feedback, other than that I mostly have minor comments.

@felixarntz felixarntz added this to the 1.3.0 milestone Jun 28, 2022
@felixarntz felixarntz removed the no milestone PRs that do not have a defined milestone for release label Jun 28, 2022
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.

@mukeshpanchal27 Thanks for the updates, the perflab_can_load_module() behavior looks good now.

I left some replies on the relevant comment threads above around how to handle the additional logic about whether a module can be loaded. TLDR I think we should add a new perflab_get_active_and_valid_modules() function which calls perflab_get_active_modules() and then further filters out any modules that cannot be loaded. All the additional checks can happen in that function, and most code that currently calls perflab_get_active_modules() should then call perflab_get_active_and_valid_modules() instead.

@mukeshpanchal27
Copy link
Member Author

@felixarntz Thanks for the review. I have implemented the review changes. Can you please review it again and let me know if it needs any changes?

Copy link
Contributor

@jjgrainger jjgrainger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mukeshpanchal27 added a comment related to a couple of the tests. It would be good to get @felixarntz input on this.

Copy link
Contributor

@jjgrainger jjgrainger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mukeshpanchal27 test look good now 👍

admin/load.php Outdated
?>
<?php if ( ! $can_load_module ) { ?>
<input type="checkbox" id="<?php echo esc_attr( "{$base_id}_enabled" ); ?>" aria-describedby="<?php echo esc_attr( "{$base_id}_description" ); ?>" disabled>
<input type="hidden" name="<?php echo esc_attr( "{$base_name}[enabled]" ); ?>" value="<?php echo $enabled ? '1' : ''; ?>">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be worth fallback to 0 instead of an empty string as the value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. For now, I have updated PR accordingly.

@felixarntz Do we need to set an empty value here?

@mukeshpanchal27 mukeshpanchal27 requested a review from mitogh July 4, 2022 08:20
Copy link
Member

@mitogh mitogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work 👍

@mukeshpanchal27
Copy link
Member Author

The PR needs a final review from @felixarntz.

@mukeshpanchal27 mukeshpanchal27 self-assigned this Jul 6, 2022
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.

Nice work! LGTM pending final review from Felix.

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.

@mukeshpanchal27 Looks good now, mostly a few last nitpicks and minor things to improve around the tests.

load.php Outdated
* @param array $modules List of active module slugs.
* @return array List of active valid module slugs.
*/
function perflab_get_valid_modules( array $modules = array() ) {
Copy link
Member

@felixarntz felixarntz Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things about this function:

  • I would say the get in the name is a bit confusing, since it filters an existing input variable rather than getting a distinct value from somewhere. So I think a better name would be perflab_filter_valid_modules(). Or, we change this implementation to just be for a single module, e.g. perflab_is_valid_module( $module ), and then you could call it via array_filter( perflab_get_active_modules(), 'perflab_is_valid_module' ).
  • Why is there a default? I would say this should rather be a required parameter, especially since calling it without any value is pointless since it would always just return the empty array then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback.

I like the perflab_is_valid_module( $module ) approach instead of the function name change. Now we should have passed a valid module slug. I have updated unit tests according to these changes.

@mukeshpanchal27
Copy link
Member Author

Thanks for the feedback @felixarntz, I have addressed the feedback and updated the PR and unit tests accordingly.

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.

@mukeshpanchal27 This is looking good now, thank you for the updates!

I left a few last suggestions to further improve the tests, but this is pretty much good to go.

Comment on lines 154 to 166
public function test_empty_module_for_perflab_is_valid_module() {
// Assert that it return null for empty module.
$this->assertEmpty( perflab_is_valid_module( '' ) );
}

/**
* @dataProvider provider_dummy_valid_modules
*/
public function test_perflab_is_valid_module( $dummy_module ) {
$output = perflab_is_valid_module( $dummy_module );
$this->assertNotEmpty( $output );
$this->assertIsString( $output );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, these assertions should be using assertFalse or assertTrue based on the alternate return type.

Also, it would be more efficient to combine these two tests into one. Both could use the same @dataProvider, you could include the empty string in there, and then every data set could also include the expected true or false. You could use assertSame for that, similarly to how you have it below for the perflab_can_load_module tests.

Also it would be great if you could use the same method name for the data provider method, except replacing test_ with data_ (see other comment below).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I removed the empty module test and merged it into test_perflab_is_valid_module so it tests all scenarios. For this test, I use @dataProvider data_perflab_is_valid_module because we can't test an empty module in test_perflab_can_load_module test.

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.

@mukeshpanchal27 Two super-minor nit-picks, but this is looking very solid now. Great work!

I'll just add those quickly, it's basically good to merge.

@felixarntz felixarntz merged commit 86f53a5 into trunk Jul 8, 2022
@felixarntz felixarntz deleted the fix/293-mechanism-not-load-module branch July 8, 2022 17:46
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] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement mechanism to not load module if core version is available
6 participants