Hi ctrlaltdelete
Have you tried disabling flushing?
https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/cache/#disable-flushing
Try it with this in your (child) theme’s functions.php
add_filter( 'related_posts_by_taxonomy_cache_args', 'rpbt_disable_cache_flush' );
function rpbt_disable_cache_flush( $args ) {
// Disable automatic flushing from actions
$args['flush_manually'] = true; // bool.
// Disable automatic flushing after a time limit
$args['expiration'] = 0; // time in seconds (0 == no expiration).
return $args;
}
add_action( 'wp_loaded', 'rpbt_flush_cache', 11 );
function rpbt_flush_cache() {
// Get the transient to manually flush the cache
$flush_cache = get_transient( 'rpbt_related_posts_flush_cache_manually' );
if ( ! $flush_cache ) {
// Transient doesn't exist
// Flush cache
km_rpbt_flush_cache();
// Set transient to expire in 7 days
set_transient( 'rpbt_related_posts_flush_cache_manually', 1, DAY_IN_SECONDS * 7 );
}
}
Perfect thanks i’ll implement it!
There are also other query optimization options to take into consideration for larger sites.
See: https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/query-optimization/
Hello thanks for the info. I added:
add_filter( 'related_posts_by_taxonomy_id_query', '__return_true' );
Everything seems to work so i’ll use it.
I have these queries that aren’t very fast, does the above filter helps with that or it’s something else?
# Query_time: 0.426876 Lock_time: 0.000090 Rows_sent: 0 Rows_examined: 0
SET timestamp=1548164968;
INSERT INTO 'wp_postmeta' ('post_id', 'meta_key', 'meta_value') VALUES (134484, '_rpbt_related_posts:6375249561307eaaeef25731acbb4f17', 'a:2:{s:3:\"ids\";a:8:{i:134931;s:1:\"3\";i:134479;s:1:\"3\";i:123545;s:1:\"3\";i:137687;s:1:\"2\";i:137220;s:1:\"2\";i:137179;s:1:\"2\";i:136913;s:1:\"2\";i:136687;s:1:\"2\";}s:4:\"args\";a:3:{s:7:\"post_id\";i:134484;s:10:\"taxonomies\";a:2:{i:0;s:5:\"genre\";i:1;s:9:\"publisher\";}s:13:\"related_terms\";a:3:{i:0;i:4;i:1;i:55;i:2;i:27;}}}');
That’s the query for update_post_meta()
https://developer.ww.wp.xz.cn/reference/functions/update_post_meta/
I don’t know why this would take longer than normal. The value is not that big:
'a:2:{s:3:\"ids\";a:8:{i:134931;s:1:\"3\";i:134479;s:1:\"3\";i:123545;s:1:\"3\";i:137687;s:1:\"2\";i:137220;s:1:\"2\";i:137179;s:1:\"2\";i:136913;s:1:\"2\";i:136687;s:1:\"2\";}s:4:\"args\";a:3:{s:7:\"post_id\";i:134484;s:10:\"taxonomies\";a:2:{i:0;s:5:\"genre\";i:1;s:9:\"publisher\";}s:13:\"related_terms\";a:3:{i:0;i:4;i:1;i:55;i:2;i:27;}}}
Is this query consistently slow?
Oh, and the id query does speed up the cache but does not influence the update_post_meta() query.
It is above 0.1 secs about 200 times a day.
I guess my SQL is just too slow to INSERT. It’s probably also overloaded.
I think i need a bigger server, just look at queries before i throw $ at it.
Good point. Related posts database queries are always going to be expensive the larger the site. There comes a point where you should look for different options if it all slows down. Like a bigger server, elastic search, related posts from a service (like jetpack) or cache.
hmm now i’m thinking on getting a cheap VPS to offload search with elastic search.
Thanks for the suggestion. Not sure if i’ll manage cos seems very complicated.
The other monster queries are from “beautiful taxonomy filters”..i have no idea how big sites do it. Certainly not with that plugin.