connector: implement user cache

* Fixes the totally broken UserInfo resolution in guilds.
* Adds support for USER_UPDATE from the gateway.

Design considerations behind the user cache:

* Explicitly handle deleted user IDs by short circuiting the lookup
  logic and returning a singleton.
* The cache map is protected during HTTP requests to the Discord API.
* The nonexistence of a user is cached. This is to prevent excessive
  requests (a user can't suddenly begin existing at a given ID).

The user cache is upserted on READY, incoming messages, backfill, etc.
This commit is contained in:
Skip R
2026-02-06 13:24:26 -08:00
parent c611e8f116
commit d8ca44ecd9
6 changed files with 203 additions and 20 deletions

View File

@@ -63,6 +63,7 @@ func (dc *DiscordClient) FetchMessages(ctx context.Context, fetchParams bridgev2
if err != nil {
return nil, err
}
dc.userCache.HandleMessages(msgs)
converted := make([]*bridgev2.BackfillMessage, 0, len(msgs))
for _, msg := range msgs {