Skip to content

fix(catalog): send a sync's removals and rewrites in filters of 100 ids, not 500 - #1633

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/catalog-sync-chunks
Oct 28, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/catalog-sync-chunks

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

A catalog sync that removes or changes many products no longer risks a request too long to reach the database.

markRemoved and replaceIn in server/src/lib/catalog/sync.js put up to 500 ids in one .in() filter. PostgREST carries that filter in the URL: about 19 kB. chunked-in.js records that requests near 16 kB were often refused at the edge before they reached PostgREST. A sync that removed more than about 100 products at once, or rewrote their images and categories, could fail there and leave the catalog half written.

  • Both now split their ids with chunkIds from chunked-in.js: 100 per request, about 4 kB of URL.
  • Writes keep 500 rows per request, since their rows go in the body.

Found while writing #1632 (it deletes in 100s for the same reason).

Related issue

None. Follow-up from #1632.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

cd server && npx vitest run src/lib/catalog/sync.test.js

The new test syncs 250 products and then an empty feed. It checks that all 250 are marked removed with no .in() filter over 100 ids. With the previous chunks() it fails, since one filter carries 250 ids.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — no web change
  • yarn typecheck passes (run from web/) — no web change
  • yarn format:check passes (run from web/) — no web change
  • Changes are focused — one concern per PR

Also run in server/: npm run format, npm run lint and npm test (3,339 tests).

🤖 Generated with Claude Code

…ds, not 500

markRemoved and replaceIn put up to 500 ids in one .in() filter, which
PostgREST carries in the URL: about 19 kB, past the size chunked-in.js
found refused before it reaches PostgREST. A sync that removed or
changed more than about 100 products at once could fail there. They now
split their ids with chunkIds (100 a request); writes, whose rows go in
the body, keep 500.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk 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.

Looks good, with follow-ups.

Merge state. Clean on main, and with #1632. On the tree with both, the catalog and shopping-path tests pass (161).

Checked

  • markRemoved and replaceIn now send 100 ids a filter (chunkIds, about 4 kB of URL). Upserts and inserts keep 500 rows a request, which is right: those rows go in the body.
  • chunkIds also drops duplicate ids. Both callers pass ids that are already unique, so nothing changes there.
  • The other .in() filters on the catalog path already go through 100-id chunks (shopping-path.js readIn).
  • The new test fails when markRemoved goes back to chunks().

Follow-ups

  1. The test doesn't cover the rewrite half. The second sync is an empty feed, so no product is touched and replaceIn never runs. Putting replaceIn back on chunks() leaves every test green. A second step that changes the 250 products (a new title or product type) and checks the filter sizes on the catalog_images and catalog_product_categories deletes would cover it, as the test's title says.

Before the API deploy. Nothing changes. This is in the API's sync only.

@gkhngyk
gkhngyk merged commit dafb89c into ansvisor:main Oct 28, 2026
6 checks passed
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