-
Notifications
You must be signed in to change notification settings - Fork 116
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
Use scheduled action for resetting large record and meta tables #1543
Changes from all commits
24cd93a
48ded08
21f1ec3
6940124
b96794f
e842334
a6d2d36
1cc8b85
9c8e59b
e931533
f8083e5
6111295
12ca190
554b51c
7a83911
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,28 @@ class Plugin { | |
*/ | ||
const WP_CLI_COMMAND = 'stream'; | ||
|
||
|
||
/** | ||
* Used to check if it's a single site, not multisite. | ||
* | ||
* @const string | ||
*/ | ||
const SINGLE_SITE = 'single'; | ||
|
||
/** | ||
* Used to check if it's a multisite with the plugin network enabled. | ||
* | ||
* @const string | ||
*/ | ||
const MULTI_NETWORK = 'multisite-network'; | ||
|
||
/** | ||
* Used to check if it's a multisite with the plugin not network enabled. | ||
* | ||
* @const string | ||
*/ | ||
const MULTI_NOT_NETWORK = 'multisite-not-network'; | ||
|
||
/** | ||
* Holds and manages WordPress Admin configurations. | ||
* | ||
|
@@ -115,6 +137,9 @@ public function __construct() { | |
|
||
spl_autoload_register( array( $this, 'autoload' ) ); | ||
|
||
// Load Action Scheduler. | ||
require_once $this->locations['dir'] . '/vendor/woocommerce/action-scheduler/action-scheduler.php'; | ||
|
||
// Load helper functions. | ||
require_once $this->locations['inc_dir'] . 'functions.php'; | ||
|
||
|
@@ -336,6 +361,69 @@ public function get_client_ip_address() { | |
return apply_filters( 'wp_stream_client_ip_address', $this->client_ip_address ); | ||
} | ||
|
||
/** | ||
* Get the site type. | ||
* | ||
* This function determines the type of site based on whether it is a single site or a multisite. | ||
* If it is a multisite, it also checks if it is network activated or not. | ||
* | ||
* @return string The site type | ||
*/ | ||
public function get_site_type(): string { | ||
|
||
// If it's a multisite, is it network activated or not? | ||
if ( is_multisite() ) { | ||
return $this->is_network_activated() ? self::MULTI_NETWORK : self::MULTI_NOT_NETWORK; | ||
} | ||
|
||
return self::SINGLE_SITE; | ||
} | ||
|
||
/** | ||
* Should the number of records which need to be processed be considered "large"? | ||
* | ||
* @param int $record_number The number of rows in the {$wpdb->prefix}_stream table to be processed. | ||
* @return bool Whether or not this should be considered large. | ||
*/ | ||
public function is_large_records_table( int $record_number ): bool { | ||
/** | ||
* Filters whether or not the number of records should be considered a large table. | ||
* | ||
* @since 4.1.0 | ||
* | ||
* @param bool $is_large_table Whether or not the number of records should be considered large. | ||
* @param int $record_number The number of records being checked. | ||
*/ | ||
return apply_filters( 'wp_stream_is_large_records_table', $record_number > 1000000, $record_number ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tharsheblows Suggestion: adding a docblock comment to all custom hooks would be beneficial for developers to understand how this plugin can be adjusted :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bartoszgadomski ACK yes, I totally forgot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit 6111295 |
||
} | ||
|
||
/** | ||
* Checks if the plugin is running on a single site installation. | ||
* | ||
* @return bool True if the plugin is running on a single site installation, false otherwise. | ||
*/ | ||
public function is_single_site() { | ||
return self::SINGLE_SITE === $this->get_site_type(); | ||
} | ||
|
||
/** | ||
* Check if the plugin is activated on a multisite installation but not network activated. | ||
* | ||
* @return bool True if the plugin is activated on a multisite installation but not network activated, false otherwise. | ||
*/ | ||
public function is_multisite_not_network_activated() { | ||
return self::MULTI_NOT_NETWORK === $this->get_site_type(); | ||
} | ||
|
||
/** | ||
* Check if the plugin is activated on a multisite network. | ||
* | ||
* @return bool True if the plugin is network activated on a multisite, false otherwise. | ||
*/ | ||
public function is_multisite_network_activated() { | ||
return self::MULTI_NETWORK === $this->get_site_type(); | ||
} | ||
|
||
/** | ||
* Enqueue a script along with a stylesheet if it exists. | ||
* | ||
|
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.
@tharsheblows There's a risk of conflict if this package was loaded by another plugin. Should this be preceded with
function_exists
call (or something similar) to only load this dependency if it has not been loaded by another plugin earlier?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.
@bartoszgadomski Action Scheduler works when included multiple times! It's a clever library – it loads the most recent version requested so all of the functions expected are available. Eg latest version does it like this