| @@ -1,29 +1,32 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | require_once(dirname(__FILE__) . '/admin-ui.php'); |
| 3 | 3 | |
| 4 | 4 | class FeedWordPressPerformancePage extends FeedWordPressAdminPage { |
| 5 | - public function __construct() { | |
| 5 | + function FeedWordPressPerformancePage () { | |
| 6 | 6 | // Set meta-box context name |
| 7 | - parent::__construct('feedwordpressperformancepage'); | |
| 7 | + FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressperformancepage'); | |
| 8 | 8 | $this->dispatch = 'feedwordpress_performance'; |
| 9 | 9 | $this->filename = __FILE__; |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | - public function has_link () { return false; } | |
| 12 | + function has_link () { return false; } | |
| 13 | 13 | |
| 14 | 14 | function display () { |
| 15 | + global $wpdb, $wp_db_version, $fwp_path; | |
| 16 | + global $fwp_post; | |
| 17 | + | |
| 15 | 18 | if (FeedWordPress::needs_upgrade()) : |
| 16 | 19 | fwp_upgrade_page(); |
| 17 | 20 | return; |
| 18 | 21 | endif; |
| 19 | - | |
| 22 | + | |
| 20 | 23 | // If this is a POST, validate source and user credentials |
| 21 | 24 | FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_performance', /*capability=*/ 'manage_options'); |
| 22 | - | |
| 25 | + | |
| 23 | 26 | if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') : |
| 24 | - $this->accept_POST(); | |
| 25 | - do_action('feedwordpress_admin_page_performance_save', null, $this); | |
| 27 | + $this->accept_POST($fwp_post); | |
| 28 | + do_action('feedwordpress_admin_page_performance_save', $GLOBALS['fwp_post'], $this); | |
| 26 | 29 | endif; |
| 27 | 30 | |
| 28 | 31 | //////////////////////////////////////////////// |
| 29 | 32 | // Prepare settings page /////////////////////// |
| @@ -37,9 +40,9 @@ | ||
| 37 | 40 | <?php |
| 38 | 41 | $boxes_by_methods = array( |
| 39 | 42 | 'performance_box' => __('Performance'), |
| 40 | 43 | ); |
| 41 | - | |
| 44 | + | |
| 42 | 45 | foreach ($boxes_by_methods as $method => $title) : |
| 43 | 46 | add_meta_box( |
| 44 | 47 | /*id=*/ 'feedwordpress_'.$method, |
| 45 | 48 | /*title=*/ $title, |
| @@ -51,9 +54,9 @@ | ||
| 51 | 54 | do_action('feedwordpress_admin_page_performance_meta_boxes', $this); |
| 52 | 55 | ?> |
| 53 | 56 | <div class="metabox-holder"> |
| 54 | 57 | <?php |
| 55 | - do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this); | |
| 58 | + fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this); | |
| 56 | 59 | ?> |
| 57 | 60 | </div> <!-- class="metabox-holder" --> |
| 58 | 61 | </div> <!-- id="post-body" --> |
| 59 | 62 | |
| @@ -60,30 +63,36 @@ | ||
| 60 | 63 | <?php |
| 61 | 64 | $this->close_sheet(); |
| 62 | 65 | } /* FeedWordPressPerformancePage::display () */ |
| 63 | 66 | |
| 64 | - function accept_POST () { | |
| 65 | - global $feedwordpress; | |
| 66 | - | |
| 67 | - if ( ! is_null( FeedWordPress::post( 'create_index' ) ) ) : | |
| 67 | + function accept_POST ($post) { | |
| 68 | + if (isset($post['create_index'])) : | |
| 68 | 69 | FeedWordPress::create_guid_index(); |
| 69 | 70 | $this->updated = __('guid column index created on database table.'); |
| 70 | 71 | endif; |
| 71 | - if ( ! is_null( FeedWordPress::post( 'remove_index' ) ) ) : | |
| 72 | + if (isset($post['remove_index'])) : | |
| 72 | 73 | FeedWordPress::remove_guid_index(); |
| 73 | 74 | $this->updated = __('guid column index removed from database table.'); |
| 74 | 75 | endif; |
| 75 | 76 | |
| 76 | - if ( ! is_null( FeedWordPress::post( 'clear_cache' ) ) ) : | |
| 77 | - $N = $feedwordpress->clear_cache(); | |
| 77 | + if (isset($post['clear_cache'])) : | |
| 78 | + $N = FeedWordPress::clear_cache(); | |
| 78 | 79 | $feeds = (($N == 1) ? __("feed") : __("feeds")); |
| 79 | - $this->updated = sprintf( __("Cleared %d cached %s from WordPress database."), $N, $feeds ); | |
| 80 | + $this->updated = sprintf(__("Cleared %d cached %s from WordPress database."), $N, $feeds); | |
| 80 | 81 | endif; |
| 81 | - | |
| 82 | + | |
| 83 | + if (isset($post['optimize_in'])) : | |
| 84 | + update_option('feedwordpress_optimize_in_clauses', true); | |
| 85 | + $this->updated = sprintf(__("Enabled optimizing inefficient IN clauses in SQL queries.")); | |
| 86 | + elseif (isset($post['optimize_out'])) : | |
| 87 | + update_option('feedwordpress_optimize_in_clauses', false); | |
| 88 | + $this->updated = sprintf(__("Disabled optimizing inefficient IN clauses in SQL queries.")); | |
| 89 | + endif; | |
| 82 | 90 | } /* FeedWordPressPerformancePage::accept_POST () */ |
| 83 | 91 | |
| 84 | - static function performance_box ($page, $box = NULL) { | |
| 85 | - | |
| 92 | + /*static*/ function performance_box ($page, $box = NULL) { | |
| 93 | + $optimize_in = get_option('feedwordpress_optimize_in_clauses', false); | |
| 94 | + | |
| 86 | 95 | // Hey ho, let's go... |
| 87 | 96 | ?> |
| 88 | 97 | <table class="editform" width="100%" cellspacing="2" cellpadding="5"> |
| 89 | 98 | <tr style="vertical-align: top"> |
| @@ -93,9 +102,9 @@ | ||
| 93 | 102 | and force FeedWordPress to make a fresh scan for updates on syndicated feeds.</p></td></tr> |
| 94 | 103 | |
| 95 | 104 | <tr style="vertical-align: top"> |
| 96 | 105 | <th width="33%" scope="row">Guid index:</th> |
| 97 | -<td width="67%"><?php if ( !FeedWordPress::has_guid_index()) : ?> | |
| 106 | +<td width="67%"><?php if (!FeedWordPress::has_guid_index()) : ?> | |
| 98 | 107 | <input class="button" type="submit" name="create_index" value="Create index on guid column in posts database table" /> |
| 99 | 108 | <p>Creating this index may significantly improve performance on some large |
| 100 | 109 | FeedWordPress installations.</p> |
| 101 | 110 | <?php else : ?> |
| @@ -106,8 +115,35 @@ | ||
| 106 | 115 | <input class="button" type="submit" name="remove_index" value="Remove index on guid column in posts database table" /> |
| 107 | 116 | |
| 108 | 117 | <?php endif; ?> |
| 109 | 118 | |
| 119 | +<tr style="vertical-align: top"> | |
| 120 | +<th width="33%" scope="row">Optimize IN clauses:</th> | |
| 121 | +<td width="67%"><?php if (!$optimize_in) : ?> | |
| 122 | +<input class="button" type="submit" name="optimize_in" value="Optimize inefficient IN clauses in SQL queries" /> | |
| 123 | + | |
| 124 | +<p><strong>Advanced setting.</strong> As of releases up to 3.3.2, WordPress | |
| 125 | +still generates many SQL queries with an extremely inefficient use of the IN | |
| 126 | +operator (for example, <code>SELECT user_id, meta_key, meta_value FROM | |
| 127 | +wp_usermeta WHERE user_id IN (1)</code>). When there is only one item in the | |
| 128 | +set, the IN operator is unnecessary; and inefficient, because it prevents SQL | |
| 129 | +from making use of indexes on the table being queried. Activating this setting | |
| 130 | +will cause these queries to get rewritten to use a simple equality operator when | |
| 131 | +there is only one item in the set (for example, the example query above would be | |
| 132 | +rewritten as <code>SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE | |
| 133 | +user_id = 1</code>).</p> | |
| 134 | + | |
| 135 | +<p><strong>Note.</strong> This is an advanced setting, which affects WordPress's | |
| 136 | +database queries at a very low level. The change should be harmless, but | |
| 137 | +proceed with caution, and only if you are confident in your ability to restore | |
| 138 | +your WordPress installation from backups if something important should stop | |
| 139 | +working.</p> | |
| 140 | + | |
| 141 | +<?php else : ?> | |
| 142 | +<input class="button" type="submit" name="optimize_out" value="Disable optimizing inefficient IN clauses" /> | |
| 143 | +<p>You can use this setting to disable any attempts by FeedWordPress to optimize | |
| 144 | +or rewrite WordPress's SQL queries.</p> | |
| 145 | +<?php endif; ?></td> | |
| 110 | 146 | </tr> |
| 111 | 147 | |
| 112 | 148 | </td> |
| 113 | 149 | </tr> |