# Reduce DB load upon initial connection due to channel loading \(\#12500\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/279c5ab81fec07fb3e116bfbb4e30023720b43f8)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 279c5ab81fec07fb3e116bfbb4e30023720b43f8

Requested commit: 279c5ab81fec07fb3e116bfbb4e30023720b43f8

Commit: 279c5ab81fec07fb3e116bfbb4e30023720b43f8

Tree: 5d292ad22b062d48d04f2a2730ca802f2db786e9

Author: Max Brunsfeld

Committer: GitHub

## Message

```
Reduce DB load upon initial connection due to channel loading (#12500)

#### Lazily loading channels

I've added a new RPC message called `SubscribeToChannels` that the
client now sends when it first renders the channels panel. This causes
the server to load the channels for that client and send updates to that
client as channels are updated. Previously, the server did this upon
connection.

For backwards compatibility, the server will inspect clients' version,
and continue to do this work immediately for old clients.

#### Optimizations

Running collab locally, I realized that upon connecting, we were running
two concurrent transactions that *both* queried the `channel_members`
table: one for loading your channels, and one for loading your channel
invites. I've combined these into one query. In addition, we now use a
join to load channels + members, as opposed to two separate queries.
Even though `where id in` is efficient, it adds an extra round trip to
the database, keeping the transaction open for slightly longer.

Release Notes:

- N/A
```

## Parents

- [99901801f4dbf611dfaddbb97c5da5a7d2b89761](https://git.cafe/gitcafe/zed/commit/99901801f4dbf611dfaddbb97c5da5a7d2b89761?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/279c5ab81fec07fb3e116bfbb4e30023720b43f8?format=markdown)
