Repository navigation
Read sitemap products in projected batches instead of whole documents - #971
Merged
Merged
Conversation
The sitemap task loaded every visible product as a full document in one query. GetSitemapProductsQuery returns only the id, translated SeName, first picture and last change, and pages by product id so each batch starts after the previous one.
…en batches LiteDB materialises the whole collection on every query, so batching there read the catalog once per batch; the query now returns the rest of it in one go. The batch loop passes the command's cancellation token, and a null CustomerGroupIds no longer throws.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Type: bugfix (performance)
Issue
The Sitemap XML task sent
GetSearchProductsQuerywith the defaultPageSize = int.MaxValue, so every visible product of the store was read as a full document (descriptions, all translations, attributes, tier prices...) in a single query, plus a count, just to build one URL per product. On a large catalog this is the task's whole memory peak.Solution
GetSitemapProductsQuery(handled in Grand.Business.Catalog) returnsSitemapProduct(Id, SeName, PictureId, UpdatedOnUtc)only. It applies the same visibility rules the sitemap used before: published, visible individually, available now, store limitation and ACL for the given customer groups (guests).$match→$sort {_id}→$limit→$project, with$filteronLocalesso only the SeName in the requested language leaves the database._id > last id of the previous batch), no skip and no count per batch.GetSitemapXmlCommandHandler.GetProductUrlsreads batches of 1000 until a short one comes back.Products in the sitemap are now ordered by id instead of creation date; search engines ignore the order.
Breaking changes
None.
GetSearchProductsQueryis unchanged.Testing
GetSitemapProductsQueryHandlerTests(MongoDB): visibility filters, projection (translated SeName with fallback, first picture, last change), paging by id.GetSitemapXmlCommandHandlerTests: a full batch makes the handler read the next one after its last product.sitemap.xmlproduct entries with the previous output - same set of URLs.