Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions admin/class-scans-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ function ( $item ) {
$rule_query = new Issues_Query(
[
'rule_slugs' => [ $rule_slug ],
'post_types' => Settings::get_scannable_post_types(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The function Settings::get_scannable_post_types() is called multiple times within the summary method (here inside a loop, and on lines 199, 206, 216, 227, 240, and 251). This can be inefficient as the function may perform database queries. To improve performance, consider calling it once at the start of the summary method, storing the result in a variable, and reusing that variable throughout the method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a nice change here but it's somewhat out of scope of the actual thing being fixed here.

The method does make a query to get an option and then processes it but the option is autoloaded so only retrieved once from database then from memory on subsequent calls.

],
1,
Issues_Query::FLAG_INCLUDE_ALL_POST_TYPES
1
);

if ( $rule_query->count() ) {
Expand All @@ -195,8 +195,9 @@ function ( $item ) {
}
$data['rules_passed'] = $this->rule_count - $data['rules_failed'];

$data['passed_percentage'] = 100;
if ( $data['posts_scanned'] > 0 && $tests_count > 0 ) {
$data['passed_percentage'] = 'N/A';
$scannable_post_types = Settings::get_scannable_post_types();
if ( ! empty( $scannable_post_types ) && $data['posts_scanned'] > 0 && $tests_count > 0 ) {
$data['passed_percentage'] = round( ( $data['rules_passed'] / $this->rule_count ) * 100, 2 );
}

Expand Down
Loading