Commit Graph
1 Commits
  • perf(clients): take one email snapshot per client fan-out, not one per inbound (#6091)
    Create and Attach called the exported AddInboundClient once per target
    inbound, and that wrapper passes a nil email→subId map, so every iteration
    re-ran getAllEmailSubIDs -- a JSON_EACH expansion over the settings blob of
    every inbound in the panel. Adding one client to 24 inbounds on a panel with
    ~300 users meant 24 full expansions of ~7k rows to answer the same question.
    
    Hoist the snapshot above the loop and call the unexported addInboundClient
    with it, exactly as BulkAttach (client_bulk.go:63) and BulkCreate
    (client_bulk.go:1151) already do. The snapshot goes stale from the second
    inbound onward, but the identity being added is the same on every iteration,
    so its own entry can only ever match itself -- checkEmailsExistForClients
    accepts an email whose stored subId equals the incoming one, and an absent
    entry is accepted too.
    
    This is the database half of #6091. The dominant cost there is the other
    half -- one synchronous 10s-capped node round-trip per remote inbound,
    which multiplies again on chained nodes -- and that needs the push batched
    per node rather than per inbound; left for a separate change.