Commit Graph
1 Commits
  • perf(clients): make SyncInbound bulk to fix large-inbound timeouts (#4885)
    Every client mutation funnels through SyncInbound, which ran O(n) DB
    round-trips per call: one SELECT per client, a Save+UpdateColumn per
    client, and a per-row junction INSERT. Toggling a single client on a
    large inbound issued thousands of queries and timed out, badly so on
    PostgreSQL where each round-trip pays TCP latency.
    
    SyncInbound now:
    - loads existing records with a single chunked SELECT ... email IN (...)
      instead of one query per client
    - writes only the records that actually changed (skips no-op Saves), so
      toggling/editing one client writes one row, not all of them
    - batch-creates new records and batch-inserts the junction rows
    
    Merge and sticky-field semantics are unchanged. Measured on PostgreSQL
    16: a single-client toggle on a 50k-client inbound drops from ~8m54s to
    ~0.9s, and seeding 50k clients from ~2m48s to ~1.6s; 200k clients sync
    in seconds.
    
    A skip-gated benchmark (web/service/sync_scale_postgres_test.go, run
    with XUI_DB_TYPE=postgres) reproduces and verifies the scaling.