Repository navigation
chore(catalog): delete catalog products removed more than 90 days ago - #1632
Merged
Merged
Conversation
A sync marks a product that left its source `removed_at` and never deleted it, so removed rows only grew. purgeRemovedCatalogProducts runs in the daily run right after the catalog source sweep and deletes products removed over 90 days ago (REMOVED_KEEP_DAYS); their variants, images and category links go with them (on delete cascade, 00278). Each delete re-checks removed_at, so a product that came back is kept. Bounded: 500 ids read per batch, 100 per delete, 10,000 a run; errors are logged and the nightly run goes on. Merchant Center item issues are left to their source's sync. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 28, 2026
gkhngyk
approved these changes
Oct 28, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups.
Merge state. Clean on main, and with #1633 (both touch sync.js, in different places). On the tree with both, the catalog and shopping-path tests pass (161).
Checked
- What a deleted product takes with it. Only three tables point at
catalog_products: variants, images and category links, allon delete cascade(00278), and each has an index onproduct_id, so a delete of 100 products stays an index walk. Images that hang off a deleted variant go too (catalog_images.variant_id, cascade, indexed). Nothing else holds a foreign key to a product: Merchant Center issues (00296) are keyed by source and offer id, category pages (00350) by category name, and the conversion tables (00287, 00288) by page. No table holds a trigger on the catalog's rows. - Shopping paths. A product id in
content_drafts.shopping_pathwith no row reads asgonein the API's rebuild (keptProducts, with the title from the stored path) and in the editor's check (getShoppingCheck). A product grid's refresh (getProductsForBlock) leaves a missing product out, the same as a removed one. - A sync that brings a product back. Each delete asks again for
removed_at < cutoff, so a product a sync made live after the read stays. A sync that read the old row before the delete still works: it writes products by upsert on(brand, source, external id), so the product comes back as a new row, and its variants, read after that write, come back under the new id. The test for this case fails when the delete'sremoved_atfilter is dropped. - Bounds. 500 ids read a batch, 100 a delete request, 10,000 a night. The loop stops on a short read or a batch that deleted nothing, so it can't spin.
- Daily run. The purge runs after the source sweep and never throws, so a failure costs only that night's purge.
Follow-ups
- Removed variants of live products are kept forever. A product that's still sold but dropped a size or colour keeps that variant row, with
removed_atset, for good. The same rule forcatalog_variants(removed over 90 days ago, product live) would close it. Their images go with them by cascade. - Categories with no products left.
catalog_categoriesrows whose products were all deleted stay.catalog_category_countsdoesn't count them (inner join), but they still sit in the table. Deleting categories with no product link left after the purge would keep it tidy. - A test for the daily run's order. Nothing checks that
runDailyTrackingcalls the purge after the sweep, or that a failed sweep still lets the purge run. A small test on that chain would stop someone from making the two run side by side. - Index once catalogs grow (as the description says). The nightly read is
removed_at < cutoff limit 500with no index onremoved_at, so it scans the table each night even when nothing is old enough. A partial index on(removed_at) where removed_at is not nullmakes it cheap.
Before the API deploy. Nothing changes. The purge lives in the API's daily run. Since the catalog is newer than 90 days, the first products it can delete are those removed 90 days after the first sync.
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.
Summary
Catalog products removed from their source more than 90 days ago are deleted. A sync marks a product that left its source
removed_atand never deletes it, so removed rows only grew. Ansvisor asked for this small guard on 2026-10-28. Each brand's catalog already has caps: uploads up to 4 MB, feeds up to 50 MB, 10 sources a brand. The per-plan product cap comes with the Product Visibility work.purgeRemovedCatalogProducts()(server/src/lib/catalog/purge.js):REMOVED_KEEP_DAYS). Their variants, images and category links go with them (on delete cascade, 00278). No other table points at a catalog product.removed_at, so a product that came back between the read and the delete stays.chunked-in.jswarns about), 10,000 products a run; the rest wait for the next night. The count is logged, and an error is logged without stopping the nightly run.What it leaves:
gone, the same as a removed one. The server's path rebuild and price read, and the web's product cards, already handle a missing product.sync.js's "never deleted" note now names the 90-day rule.Related issue
None. Ansvisor's decision (2026-10-28).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/catalog/purge.test.jsremoved_atto 100 days ago and another's to 10 days ago, then run the daily run: only the first is deleted, with its variants.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) — no web changeyarn typecheckpasses (run fromweb/) — no web changeyarn format:checkpasses (run fromweb/) — no web changeAlso run in
server/:npm run format,npm run lintandnpm test(3,342 tests).For you, @gkhngyk:
sync.js'smarkRemovedandreplaceInput up to 500 ids in one.in()(about 19 KB of URL), whichchunked-in.jssays is often refused. A sync that removes more than about 100 products at once could fail there. Chunking them by 100 can be its own fix.catalog_products (removed_at) where removed_at is not nullwould help once catalogs are large. Not needed yet.leftOut) is no longer flagged, since its catalog row is gone. Storing the url inleftOutwould keep it.🤖 Generated with Claude Code