Skip to content

Commit

Permalink
Improve upgrade routine, causing less queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevalk committed Jul 9, 2017
1 parent 81c219c commit 71b3be8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion inc/class-comment-hacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,31 @@ public function comment_redirect( $url, $comment ) {
return $url;
}

/**
* See if the option has been cached, if it is, return it, otherwise return false.
*
* @param string $option The option to check for.
*
* @since 1.3
*
* @return bool|mixed
*/
private function get_option_from_cache( $option ) {
$options = wp_load_alloptions();
if ( isset( $options[ $option ] ) ) {
return $option;
}
return false;
}

/**
* Check whether any old options are in there and if so upgrade them
*
* @since 1.0
*/
private function upgrade() {
foreach ( array( 'MinComLengthOptions', 'min_comment_length_option', 'CommentRedirect' ) as $old_option ) {
$old_option_values = get_option( $old_option );
$old_option_values = $this->get_option_from_cache( $old_option );
if ( is_array( $old_option_values ) ) {
if ( isset( $old_option_values['page'] ) ) {
$old_option_values['redirect_page'] = $old_option_values['page'];
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ See the screenshots to get an even better idea of the plugins functionality.
* Remove `[...]` from pingback / trackback excerpt in cleaned emails as that's already included by core.
* Replace link to ARIN with link to [ip-lookup.net](http://ip-lookup.net) for details about the IP.
* Refactored code for readability and code quality.
* Refactor upgrade routine to do less DB queries.

= 1.2 =

Expand Down

0 comments on commit 71b3be8

Please sign in to comment.