-
Notifications
You must be signed in to change notification settings - Fork 1
AAA Option Optimizer #271
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
Draft
ilicfilip
wants to merge
33
commits into
develop
Choose a base branch
from
filip/aaa-option-optimizer
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+170
−0
Draft
AAA Option Optimizer #271
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
38628bc
aaa option optimizer
ilicfilip cc63c1a
update is_task_completed()
ilicfilip f5b4ec3
Merge branch 'develop' into filip/aaa-option-optimizer
aristath c8b94b5
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip bbaca94
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 59a782c
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip d53d38b
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip cb170ed
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip ab9c78f
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 5f856f4
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 4a96d07
check for all auto load values
ilicfilip 44d21c9
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 09353ff
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip b6cb221
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip fe5544f
sync branch with recent changes
ilicfilip 6a05293
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 38116b0
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 603cdeb
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip cfc39a4
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip cde9125
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip d32bafc
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip b7f40a1
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 883cae3
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip a8d69af
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 338869f
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip e1e6254
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip ab79014
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip 64375aa
Merge branch 'develop' into filip/aaa-option-optimizer
aristath dbd3235
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip de3e33e
Merge branch 'develop' into filip/aaa-option-optimizer
aristath 6420274
Merge branch 'develop' into filip/aaa-option-optimizer
aristath 16945a4
Merge branch 'develop' into filip/aaa-option-optimizer
aristath ed3ab83
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
classes/suggested-tasks/local-tasks/providers/one-time/class-reduce-autoloaded-options.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| <?php | ||
| /** | ||
| * Add tasks for settings saved. | ||
| * | ||
| * @package Progress_Planner | ||
| */ | ||
|
|
||
| namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time; | ||
|
|
||
| use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time; | ||
|
|
||
| /** | ||
| * Add tasks to check if WP debug is enabled. | ||
| */ | ||
| class Reduce_Autoloaded_Options extends One_Time { | ||
|
|
||
| /** | ||
| * Whether the task is an onboarding task. | ||
| * | ||
| * @var bool | ||
| */ | ||
| protected const IS_ONBOARDING_TASK = false; | ||
|
|
||
| /** | ||
| * The provider type. | ||
| * | ||
| * @var string | ||
| */ | ||
| const CATEGORY = 'maintenance'; | ||
|
|
||
| /** | ||
| * The provider ID. | ||
| * | ||
| * @var string | ||
| */ | ||
| const PROVIDER_ID = 'reduce-autoloaded-options'; | ||
|
|
||
| /** | ||
| * The number of autoloaded options. | ||
| * | ||
| * @var int | ||
| */ | ||
| private $autoloaded_options_count = null; | ||
|
|
||
|
|
||
| /** | ||
| * The plugin active state. | ||
| * | ||
| * @var bool | ||
| */ | ||
| private $is_plugin_active = null; | ||
|
|
||
| /** | ||
| * Threshold for the number of autoloaded options. | ||
| * | ||
| * @var int | ||
| */ | ||
| private $autoloaded_options_threshold = 10; // TODO: 10 is just for testing purposes. | ||
|
Check warning on line 58 in classes/suggested-tasks/local-tasks/providers/one-time/class-reduce-autoloaded-options.php
|
||
|
|
||
| /** | ||
| * The plugin path. | ||
| * | ||
| * @var string | ||
| */ | ||
| private $plugin_path = 'aaa-option-optimizer/aaa-option-optimizer.php'; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| */ | ||
| public function __construct() { | ||
|
|
||
| $this->title = \esc_html__( 'Reduce number of autoloaded options', 'progress-planner' ); | ||
| $this->description = sprintf( | ||
| // translators: %d is the number of autoloaded options. | ||
| \esc_html__( 'There are %d autoloaded options. If you don\'t need them, consider disabling them by installing the "AAA Option Optimizer" plugin.', 'progress-planner' ), | ||
| $this->get_autoloaded_options_count(), | ||
| ); | ||
| $this->url = \admin_url( '/plugin-install.php?tab=search&s=aaa+option+optimizer' ); | ||
| $this->is_dismissable = true; | ||
| } | ||
|
|
||
| /** | ||
| * Check if the task condition is satisfied. | ||
| * (bool) true means that the task condition is satisfied, meaning that we don't need to add the task or task was completed. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function should_add_task() { | ||
| // If the plugin is active, we don't need to add the task. | ||
| if ( $this->is_plugin_active() ) { | ||
| return false; | ||
| } | ||
|
|
||
| return $this->get_autoloaded_options_count() > $this->autoloaded_options_threshold; | ||
| } | ||
|
|
||
| /** | ||
| * Check if the task is completed. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function is_task_completed() { | ||
| return $this->is_plugin_active() || $this->get_autoloaded_options_count() <= $this->autoloaded_options_threshold; | ||
| } | ||
|
|
||
| /** | ||
| * Check if the plugin is active. | ||
| * | ||
| * @return bool | ||
| */ | ||
| protected function is_plugin_active() { | ||
|
|
||
| if ( null === $this->is_plugin_active ) { | ||
| if ( ! function_exists( 'get_plugins' ) ) { | ||
| require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore requireOnce.fileNotFound | ||
| } | ||
|
|
||
| $plugins = get_plugins(); | ||
| $this->is_plugin_active = isset( $plugins[ $this->plugin_path ] ) && is_plugin_active( $this->plugin_path ); | ||
| } | ||
|
|
||
| return $this->is_plugin_active; | ||
| } | ||
|
|
||
| /** | ||
| * Get the number of autoloaded options. | ||
| * | ||
| * @return int | ||
| */ | ||
| protected function get_autoloaded_options_count() { | ||
| global $wpdb; | ||
|
|
||
| if ( null === $this->autoloaded_options_count ) { | ||
| $autoload_values = \wp_autoload_values_to_autoload(); | ||
| $placeholders = implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) ); | ||
|
|
||
| // phpcs:disable WordPress.DB | ||
| $this->autoloaded_options_count = $wpdb->get_var( | ||
| $wpdb->prepare( "SELECT COUNT(*) FROM `{$wpdb->options}` WHERE autoload IN ( $placeholders )", $autoload_values ) | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| return $this->autoloaded_options_count; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 doubt normal users will understand or know whether they need autoloading options or not, and we should make it clear that this is a performance improvement
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 agree, wording was just a placeholder during WIP and it needs to be improved - that is the one for @tacoverdo and @irisgue , if we decide to merge it 😄