Public Ticket #3983591

Performance Bottlenecks Due to Repeated B2B Rule and Visibility Queries (Query Monitor Findings)

Closed
Comments
10 Tickets 7
Jonas Pedersen started the conversation 1 year ago on May 5, 2025 at 10:56am

Hi B2BKing Support,

I’m using the B2BKing plugin and have run into some performance issues identified with the Query Monitor plugin. I’ve noticed that many of the plugin’s database queries are being executed multiple times per page load, especially those related to product visibility rules and custom fields.

Examples of repeated queries:

  • SELECT * FROM wp_postmeta WHERE meta_key = 'b2bking_rule_who' ...

  • SELECT d_posts.ID FROM wp_posts ... WHERE post_type = 'b2bking_rule' ...

  • WC_Product_Data_Store_CPT->get_product_id_by_sku repeated multiple times

  • Multiple LIKE-based meta queries involving visibility groups

These queries appear to be repeated across various components like:

  • b2bking_product_categories_visibility_rules_productfilter

  • b2bking_disable_payment_methods_dynamic_rule

  • b2bking_get_rules_for_user

They significantly impact performance on product and checkout pages.

Questions:

  • Is there a way to optimize or cache these queries?

  • Could you recommend hooks or filters that allow me to cache rules per user/session using transients or object cache?

  • Are there known strategies for minimizing the number of visibility or rule queries per request?

Thanks in advance for any performance guidance or optimizations you can recommend.

Best regards,

1
2,762
KingsPlugins replied 1 year ago on May 10, 2025 at 2:17pm

Hello Jonas,

A few thoughts and notes:

  • When using visibility, please make sure to enable B2BKing -> Settings -> Other -> Product Visibility Cache
  • Sometimes it can help to add this code snippet to the site add_filter('b2bking_use_simple_query_system','__return_true'); - it makes rules use some simpler queries initially which can help improve performance on some sites.

Other than that, functions like 

  • b2bking_product_categories_visibility_rules_productfilter 

  • b2bking_disable_payment_methods_dynamic_rule

already use transients and are supposed to run only if the plugin cannot find a transient with that info:

2053180773.png

1514727045.png

2112743046.png

In the case of 

  • b2bking_get_rules_for_user

I cannot find this in the code so I think it might be a custom function.

 

It's difficult to say what exactly happens. I'm not sure if there's something invalidating the cache, preventing the cache from saving, or some other conflict or unexpected interaction.

 

Something to note is that in some cases B2BKing doesn't work well with object caches, to the point where the performance may be faster without the object cache. If you use one, I would suggest to try running a comparative test, with and without it, I wonder if maybe it is negatively affecting how transients are retrieved.

 

Kind regards,

Stefan

 

Sign In