Speed up the products table publication #5128
Merged
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.
Impact: minor
Type: performance
Issue
Loading and paging the products table in the operator UI is slow with large Products collection.
Solution
Results testing Mongo queries directly with 64654 top-level products:
Sorting slows things down a bit as expected, but it is using the index so I don’t think there’s much to be done there. And 15ms query on the first page is respectable.
The query (without any fancy filtering) seems fine.
When I comment out the
Counts.publish
the table is much faster. So I think most of the blame is with publishing the count. We could look into using https://atmospherejs.com/natestrauser/publish-performant-counts package instead. But since we're soon moving this to GraphQL, I'd rather not introduce a new Meteor package.For now, I'm seeing improvements by adding
noReady
andnonReactive
options to the counts publication, and removing variants from the result set. We no longer need the variants included due to recent UI changes.Other changes
With the variants no longer being published, this exposed an issue with the client side money formatting where there would end up being two currency symbols in the formatted string. I rewrote that function to use code similar to what we use on the server.
Breaking changes
None really but any custom plugins with operator UI components that are relying on variants being published might need updating.
Testing
Go to the Products table in operator UI with a large number of top-level products in the database. Verify that it loads in a few seconds and takes only a few seconds to switch between pages.