PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Very slow [woof_text_filter] searches

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

https://zederkof.no/

This page is using woof text filter search, but it is far too slow - there are a lot of products and categories - do you reckon the only way to speed up is server side or is there anything I can do in the plugin?

Thanks.

Hello Eirik

Place please purchase code of the plugin into the secret area of this ticket

https://share.pluginus.net/image/i20230222134241.png
https://share.pluginus.net/image/i20230222134615.png
https://share.pluginus.net/image/i20230222134511.png

The slow performance is because the plugin uses SQL JOIN method by default. For databases with 3000+ products, the post__in method is much faster. Solution - Add this single line to your theme's functions.php:

add_filter('woof_husky_query_post__in', '__return_true');

This will enable the faster search method that's already built into the plugin. Expected improvement: From 10+ seconds to 1-3 seconds.
Please test and let me know the results, if no luck please share ftp access to this or staged site clone to make experiments with the code

 

Hello,

Added the purchase code,

It did work and make the search faster - but sorting by checking product categories is still slow - can this be applied to any sorting process in Husky?

Thanks!

Hello Eirik

Good news that the text search is faster now!

For the slow ordering by categories, the issue is with database queries on term_relationships table. Here's the solution:
Add MySQL indexes for category ordering, add this code to your functions.php:

add_action('admin_init', 'add_woof_category_indexes', 999);

function add_woof_category_indexes() {
global $wpdb;

if (get_option('woof_category_indexes_added')) {
return;
}

$wpdb->query("
ALTER TABLE {$wpdb->term_relationships}
ADD INDEX woof_cat_idx (object_id, term_taxonomy_id)
");

$wpdb->query("
ALTER TABLE {$wpdb->term_taxonomy}
ADD INDEX woof_tax_idx (taxonomy, term_id)
");

update_option('woof_category_indexes_added', true);
}

Alternative - Cache category queries:
Add this code to cache category filtering results:

add_filter('woof_get_query_args', 'cache_woof_category_queries', 10, 1);

function cache_woof_category_queries($args) {

if (empty($_GET['product_cat'])) {
return $args;
}

$cache_key = 'woof_cat_' . md5(serialize($_GET));
$cached_ids = get_transient($cache_key);

if ($cached_ids !== false) {
$args['post__in'] = $cached_ids;
return $args;
}

return $args;
}

add_action('pre_get_posts', 'store_woof_category_cache', 999);

function store_woof_category_cache($query) {
if (!empty($_GET['product_cat']) && !empty($query->posts)) {
$cache_key = 'woof_cat_' . md5(serialize($_GET));
$post_ids = wp_list_pluck($query->posts, 'ID');
set_transient($cache_key, $post_ids, HOUR_IN_SECONDS);
}
}

Expected improvement: Category ordering should drop from several seconds to < 1 second. Try the first solution (indexes) first - it's the most effective.

 

Hello,

Thanks a lot - I tested alternative one and it seems to have improved it.

Thanks for excellent support!

Welcome :)