catalog: Reduce search table write churn during stitching

Replace the bulk DELETE + INSERT of all search rows with a minimal sync
that only touches rows that actually changed:

- Postgres: single writable CTE with unnest — DELETE stale rows and
  INSERT new ones in one atomic statement using snapshot isolation
- MySQL: temporary table merge with deadlock retry (errno 1213)
- SQLite: unchanged bulk replace (sufficient for dev/test)

For a typical user entity with ~200 search rows where one annotation
changed, this reduces the operation from ~400 row writes to ~2.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
This commit is contained in:
Fredrik Adelöw
2026-03-30 14:02:01 +02:00
parent 0336f92de8
commit 9da73bf599
4 changed files with 494 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Reduced search table write churn during stitching by syncing only changed rows instead of doing a full delete and re-insert. On Postgres this uses a single writable CTE, on MySQL a temporary table merge with deadlock retry, and on SQLite the previous bulk replace.