Skip to content

Read sitemap products in projected batches instead of whole documents - #971

Merged
KrzysztofPajak merged 2 commits into
developfrom
perf/sitemap-product-batches
Oct 21, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
perf/sitemap-product-batches

Conversation

@KrzysztofPajak

Copy link
Copy Markdown
Member

Type: bugfix (performance)

Issue

The Sitemap XML task sent GetSearchProductsQuery with the default PageSize = 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

  • New GetSitemapProductsQuery (handled in Grand.Business.Catalog) returns SitemapProduct(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).
  • The projection runs on the server: $match → $sort {_id} → $limit → $project, with $filter on Locales so only the SeName in the requested language leaves the database.
  • Keyset paging by product id (_id > last id of the previous batch), no skip and no count per batch.
  • GetSitemapXmlCommandHandler.GetProductUrls reads 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. GetSearchProductsQuery is unchanged.

Testing

  1. GetSitemapProductsQueryHandlerTests (MongoDB): visibility filters, projection (translated SeName with fallback, first picture, last change), paging by id.
  2. GetSitemapXmlCommandHandlerTests: a full batch makes the handler read the next one after its last product.
  3. Manually: run the "Generate sitemap XML" scheduled task and compare sitemap.xml product entries with the previous output - same set of URLs.

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.
Copilot AI balanced review requested due to automatic review settings October 21, 2026 19:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…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.
@KrzysztofPajak
KrzysztofPajak merged commit fc4e4cd into develop Oct 21, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the perf/sitemap-product-batches branch October 21, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants