Skip to content

Super Speedy Filters should use my object_ancestors table even if we're not checking for stock #60

Open

Description

@dhilditch

https://i.imgur.com/7NHdXQJ.png

  1. This needs to be on a large store to reproduce the issue, e.g. I have 1 million products locally
  2. Enable stock check from Settings > SSF
  3. Load /shop/ - see that the main query is quite fast, e.g. 0.1s
  4. Change the stock check from Settings > SSF to NOT check in stock by default
  5. Reload /shop/ - on my local this now takes 7+ seconds because they have the code added to check that the products are not 'hidden from catalog'

To fix:

  1. Add visible_in_catalog column to object_ancestors - code needs to go in table rebuild and in table maintenance functions - double check it gets updated and maintained correctly by changing a products catalog visibility
  2. Adjust the pre_get_posts function to use my object_ancestors table, even on /shop/ when no stock check is running - i.e. it should join to object_ancestors on visible_in_catalog=1 and it should remove the NOT IN for term_relationships - code already exists to do this term_relationships removal and swap that slow code with my object_ancestors joins
  3. Double check if the instock flag on object_ancestors also reflects 'visible in catalog' - I think i might have overloaded the purpose of this field to contain 'instock' and 'visible in catalog'.
  4. Add an option to settings too so that users can choose whether 'back order' items should be considered instock - currently they are (new bug specific to this request created at Super Speedy Filters needs a new option in the Main tab below the 'check in stock' option to let admins choose how to treat 'backorders' #61 )

End result should be /shop/ being 0.1s main query for 1 million products with or without default stock check enabled.

Activity

  1. dhilditch commented on Jan 26, 2024

    @dhilditch
    ContributorAuthor

    Note re: 3 above, please investigate this first in the code and find out if the visible in catalog is included in the instock setting, I think it is.

    visible in catalog is checked in a really slow way by woocommerce by creating a taxonomy for catalog_visibility with terms like 'hidden from search' and 'hidden from catalog' etc and then in the main query they check that products are NOT in that taxonomy. NOT IN is a slow SQL query pretty much always, depending on the rest of the query, but anyway - check if this is used in the current table maintenance code when setting the instock bit value and if you have any confusion contact me on discord.

  2. added
    bug
    on Feb 14, 2024
  3. voodoo911 commented on Feb 19, 2024

    @voodoo911

    @dhilditch said he will solve that issue

  4. self-assigned this
    on Feb 23, 2024
  5. dhilditch commented on Feb 23, 2024

    @dhilditch
    ContributorAuthor

    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_wc_product_meta_lookup wc_product_meta_lookup ON wp_posts.ID = wc_product_meta_lookup.product_id WHERE 1=1 AND ( wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN (7,9) ) ) AND wp_posts.post_type = 'product' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wc_product_meta_lookup.min_price ASC, wc_product_meta_lookup.product_id ASC LIMIT 0, 12

    Above takes 6.8s on my local

  6. dhilditch commented on Feb 23, 2024

    @dhilditch
    ContributorAuthor

    Whereas when joined to object_ancestors to limit the stock, it takes 0.05 seconds.

    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_wc_product_meta_lookup wc_product_meta_lookup ON wp_posts.ID = wc_product_meta_lookup.product_id JOIN wp_fww_object_ancestorsas oa1 ONwp_posts.id = oa1.ID and oa1.instock = 1 and oa1.taxonomy = 'product_cat' WHERE 1=1 AND wp_posts.post_type = 'product' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wc_product_meta_lookup.min_price ASC, wc_product_meta_lookup.product_id ASC LIMIT 0, 12

  7. voodoo911 commented on Feb 23, 2024

    @voodoo911

    @dhilditch Should I implement that code to plugin ?

  8. dhilditch commented on Feb 23, 2024

    @dhilditch
    ContributorAuthor

    This one I'd like to look at a bit more @voodoo911 we need to be careful with this.

  9. dhilditch commented on Feb 23, 2024

    @dhilditch
    ContributorAuthor
  10. dhilditch commented on Jul 28, 2026

    @dhilditch
    ContributorAuthor

    Checked against SSF 6.40.4. The shared object_ancestors table is now detected, but the fast path is still entered through the stock-check branch and the table has no separate visible_in_catalog value. Suggested fix: store catalogue visibility independently and use the ancestor table whenever it is ready, regardless of the stock-check setting.

  11. dhilditch commented on Sep 16, 2026

    @dhilditch
    ContributorAuthor

    Retested on SSF 6.54.1 (beca1c0), WooCommerce 10.5.3, HPOS enabled and Storefront, with a dedicated synthetic catalogue of 1,000,000 published products. The current-core index rebuild completed before testing.

    Keeping this open. The unfiltered shop still bypasses object_ancestors and retains the visibility NOT IN query. The original 0.1s versus 7s timing gap did not reproduce, but the stock-enabled baseline is also incorrect:

    Request Main query time Products found SSF query active
    /shop/, Check Stock = Yes 0.527–0.610s, three requests 1,000,000 No
    /shop/, Check Stock = No 0.563–0.605s, three requests 1,000,000 No
    /shop/?stock-status=instock, default No 58.544s, one request 995,037 Yes

    The catalogue contains 995,037 in-stock and 4,963 out-of-stock products. The explicit stock request uses the OA join and returns the correct count; the default stock setting on the unfiltered shop does not. The stock-enabled correctness assertion fails on all three requests. No database errors were reported. Scheduled background jobs were disabled during measurement; these are local reproduction timings, not a controlled hardware benchmark.

    Retained environment: http://tests-issue-60.super-speedy-filters.localhost:8081/shop/ (local to my development machine). The query traces, failing check and screenshots are retained with this environment's reproduction evidence. No fix applied.

  12. dhilditch commented on Sep 16, 2026

    @dhilditch
    ContributorAuthor

    Fixed in 6.55.1, committed and pushed to core master (8623ab8).

    The unfiltered Shop now honours the default Check Stock setting. On the retained million-product fixture, off returns 1,000,000 products and on returns the independently verified 995,037 in-stock products. The HTTP regression failed before the fix and passes afterwards; the existing category archive regression also passes.

    This fixes the stock-setting bypass. The existing stock query took 22.21 seconds in this run; no query-speed improvement is claimed. Test environment: http://tests-issue-60.super-speedy-filters.localhost:8081/ . This is pushed source, not a deployed customer release.

  13. dhilditch commented on Sep 16, 2026

    @dhilditch
    ContributorAuthor

    Correction: reopening this report. Version 6.55.1 fixes the default-stock bypass discovered during reproduction, but does not implement this report's requested catalogue-visibility optimisation through object_ancestors. The original performance target and visibility maintenance still need work. The earlier closure was premature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Super Speedy Filtersbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions