SpiderOak/crypton — pull request #174 by ecto (2014-02-04 21:38:16+00:00)
Title: Container watching

Adds `container.watch()` and `container.unwatch()`. When the server is started, a Postgres client is created which runs a `LISTEN` query. During each transaction, if a` container_record` row is created, the Postgres server will `NOTIFY` for each account with a `container_session_key_share` for the container. When the server receives these notifications, if the account has an active websocket session with the server, the event will be relayed. If the container is loaded in the client's session, it will be synced. If a listener has been set, it will be called after the container has been synced.

This may be improved by selecting container records by distinct container. For example, if there is a transaction with multiple record insertions on a single container, each record will `NOTIFY` for each peer.

I'm unsure how this will work when we need to scale Postgres. We'll need to revisit the use of `pg_notify` when we cross that bridge.