| User | Post |
|
9:11 am January 30, 2012
| metal450
Member
| | | |
|
| posts 178 |
|
|
…Bah, there does still seem to be an issue though
Previously (with 1.3.44), performing a Relevanssi search i.e. for the term "Kyoto" required 333 queries in total (for an "anonymous" visitor). Switching over to 1.3.53 now requires a whopping 703. It would appear that all these extra queries are of the form:
SELECT * FROM wp_posts WHERE ID = 404 LIMIT 1
Called from: require, require_once, do_action, call_user_func_array, template_overrides, jk_load_template, include, relevanssi_do_query, relevanssi_search, apply_filters, call_user_func_array, Relevanssi_Search_Filter_RS->relevanssi_post_ok, current_user_can, call_user_func_array, WP_User->has_cap, call_user_func_array, map_meta_cap, get_post
I see that there's now an explicit Relevanssi_Search_Filter_RS running, but is there any reason why the search would require more than twice the total number of queries now as it did in 1.3.44?
|
|
|
9:14 am January 30, 2012
| metal450
Member
| | | |
|
| posts 178 |
|
|
…Er, I shouldn't say "all" these extra queries as I just went through the first few - the initial bulk of them are of that form though (and I'd imagine you already know what the others are, if they're in fact something else ;))
|
|
|
9:46 am January 30, 2012
| Kevin
Admin
| | | |
|
| posts 2503 |
|
|
Man, you sure know how to make me look good!
Try the following changes:
In relevanssi/relevanssi.php:
add:
$doc_weight = apply_filters( 'relevanssi_results', $doc_weight );
above:
if (isset($doc_weight) && count($doc_weight) > 0) {
Also change role-scoper/relavanssi-helper-front_rs.php as shown below.
|
|
|
9:52 am January 30, 2012
| Kevin
Admin
| | | |
|
| posts 2503 |
|
|
New relavanssi-helper-front_rs.php code to reduce db queries:
class Relevanssi_Search_Filter_RS {
var $valid_stati = array();
var $relevanssi_results = array();
function Relevanssi_Search_Filter_RS() {
$this->valid_stati = array_merge( get_post_stati( array( 'public' => true ) ), get_post_stati( array( 'private' => true ) ) );
remove_filter( 'relevanssi_post_ok', 'relevanssi_default_post_ok' );
add_filter( 'relevanssi_post_ok', array( &$this, 'relevanssi_post_ok' ) );
add_filter( 'relevanssi_results', array( &$this, 'relevanssi_log_results' ) );
}
function relevanssi_log_results( $arr ) {
$this->relevanssi_results = $arr;
return $arr;
}
function relevanssi_post_ok($doc) {
static $set_listed_ids = false;
if ( ! $set_listed_ids ) {
$set_listed_ids = true;
$GLOBALS['scoper']->listed_ids['post'] = array_fill_keys( array_keys($this->relevanssi_results), true );
}
if ( function_exists('relevanssi_s2member_level') ) {
if ( relevanssi_s2member_level($doc) == 0 ) return false; // back compat with relevanssi_default_post_ok, in case somebody is also running s2member
}
$status = relevanssi_get_post_status($doc);
if ( in_array( $status, $this->valid_stati ) )
$post_ok = current_user_can( 'read_post', $doc );
else
$post_ok = false;
return $post_ok;
}
}
|
|
|
10:10 am January 30, 2012
| metal450
Member
| | | |
|
| posts 178 |
|
|
That brought it down to 409 queries (versus 334 with v1.3.44, and 203 with role-scoper disabled entirely).
Still does feel like quite a hit to be honest…particularly because the very reason I'm trying to get the upgrade working is to reduce the performance impact that this plugin is having on the site overall :/ Alone it's still more than doubling the query count for a search (rather than the 60% hit of v1.3.44)…
|
|
|
10:14 am January 30, 2012
| metal450
Member
| | | |
|
| posts 178 |
|
|
Perhaps some additional functionality has been added since *.44 that I don't need, and can disable via a define to at least get back to where we were previously query-wise?
|
|
|
10:30 am January 30, 2012
| Kevin
Admin
| | | |
|
| posts 2503 |
|
|
That's probably going to stay on the back burner for a while unless you can come up with some funding.
|
|
|
10:48 am January 30, 2012
| metal450
Member
| | | |
|
| posts 178 |
|
|
How much funding do you reckon it would take to get this back to the performance of 1.3.44?
Also: Since it seems like a Relevanssi modification is needed for what we've got so far, should I contact the author and ask him to add it - or are you in touch with him already?
|
|
|
8:52 am January 31, 2012
| Kevin
Admin
| | | |
|
| posts 2503 |
|
|
If you want to send comparative query logs, that would help me determine my cost to optimize your search performance.
I have not contacted the Relevanssi author.
|
|
|
10:30 am February 6, 2012
| Kevin
Admin
| | | |
|
| posts 2503 |
|
|
This is resolved by Role Scoper 1.3.54 (currently the "development version" on wordpress.org).
metal450 reported that activating RS now reduces the number of search queries if the Relevanssi modification shown above is also applied.
|
|
|
10:34 am February 6, 2012
| metal450
Member
| | | |
|
| posts 178 |
|
|
Just curious: would that be because of RS's caching or something? Seems strange that Relevanssi+Role-Scoper actually requires FEWER queries, when it's in fact doing more!
|
|
|
10:37 am February 6, 2012
| Kevin
Admin
| | | |
|
| posts 2503 |
|
|
It's due to Role Scoper pre-populating the post cache. Subsequent get_post() calls triggered by Relevanssi code no longer require a "SELECT * FROM wp_posts WHERE ID = …"
|
|
|
10:39 am February 6, 2012
| metal450
Member
| | | |
|
| posts 178 |
|
|
Aha. Well done!
A note to others: the optimization also depends on Relevanssi adding a filter, but its author has not submitted an update yet.
|
|