Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves N/a
Impact: minor
Type: performance
Issue
When dealing with a large number of products you may or may not observe a slowdown when querying via the products query. Digging a little deeper into this one the leading causes of this is that more often than not this query results in one or more sequential scans of the products collection.
This occurs because of a default filter being applied on Products.ancestors which is used to determine whether a product is top level or not. This default is causing the generated query plan to miss all available indexes in certain situations.
Solution
In switching to an array size approach for determining whether a product has no ancestors, we are at least forcing a hit on the default index:
reaction/packages/api-plugin-products/src/index.js
Line 39 in 9d79420
However this in and of itself does not guarantee that the correct index will be used without explicitly specifying ancestors as part of a compound index or providing the engine with an index hint; whether or not we get a partial index scan without doing so against the desired index very much depends on the sort criteria being specified.