mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 08:15:55 +00:00
The push effect re-runs every time a login connects, which while a browser with many logins restores means once per account. Each run closed every client's push and set it up again: the live streams were torn down and reopened and every slow poll re-primed its baseline with a full state read (Mailbox, Email, Calendar, CalendarEvent, SieveScript) - quadratic in the number of accounts. With ten logins that was 21 stream openings and about 180 state-poll methods in the first seconds. Reconcile instead: bind the clients that are new, unbind the ones that are gone, and on an account switch re-bind only the two logins whose role changed, handing the live stream to the newly active one when it has none. Handlers are read through a ref at event time, so a binding never has to be re-created because a callback changed identity. The reconciliation is a pure function (lib/push-bindings.ts) with its own tests; the effect only supplies the callbacks.