Repository navigation
feat(plugin-gateway): add guild managers with caches keyed by id - #219
Conversation
|
Note This drawing shows
1 finding · reviewed 🟠 Guild scoped cache can write entries for another guild ·
|
There was a problem hiding this comment.
ℹ️ No critical issues — one performance note inline, plus a doc nit.
Reviewed changes
Reviewed the full diff of the single commit; ran guild-managers.test.ts and presence-resolve.test.ts locally (102 tests pass).
- Guild-scoped managers —
GuildMemberManager,RoleManager,VoiceStateManagerandPresenceManagergain anInGuildtype parameter and optionalguildId, exposed asguild.members|roles|voiceStates|presencesandclient.guilds.<name>(guildId). - Narrowed guild
cache—CachedManager#createGuildCachereturns a fullCachekeyed by the entity ID alone, sync when the client's cache is. fillGuildIdforwarding — listed methods of a guild instance delegate to the client's manager with the guild ID prepended, typed throughGuildArgs/withGuildId.channel.messages/thread.memberscache—scopeCachegivesget/has/deleteby ID alone.- Tests and docs — runtime tests over sync and Redis-backed caches, a type-level consumption test, README section and a
minorchangeset.
Checked and found sound: every public method taking a guildId is in its fillGuildId list, the ${guildId}: prefix can't collide across guilds, and forwards in guild-managers.test.ts asserts the exact forwarded arguments.
ℹ️ Nitpicks
packages/plugin-gateway/src/managers/PresenceManager.ts(class doc, around lines 19-23): the two new paragraphs say the same thing twice ("reads it by user ID alone" and "is this manager built for one guild"). Merge them into one.
claude-sonnet-5-5 | 𝕏
@wolfstar/plugin-api
@wolfstar/plugin-broker
@wolfstar/plugin-cache
@wolfstar/plugin-gateway
@wolfstar/plugin-i18next
@wolfstar/plugin-logger
@wolfstar/plugin-scheduled-tasks
@wolfstar/plugin-sharder
@wolfstar/plugin-subcommands-advanced
commit: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (30ad4c2..2048163), a single follow-up commit in CachedManager.ts.
- Counted without copying —
getSizeon a guild cache now counts prefix matches over the key iterator, with no intermediate array onMapcaches. - Safe
clear— own keys are collected before deleting, so it works for caches that can't be mutated mid-iteration. - Documented cost — the
cacheJSDoc now states thatgetSizeandclearscan every guild's keys.
The earlier perf thread is addressed and resolved. The non-anchored PresenceManager doc nit from the first review is untouched by this commit.
claude-sonnet-5-5 | 𝕏

🔗 Linked issue
No linked issue.
🧭 Context
In discord.js a guild's caches are read by a single ID:
guild.presences.cache.get(userId). Inplugin-gatewaythe members, roles, voice states and presences live in client-level managers keyed by guild and ID, so every read had to build the key first:📚 Description
GuildMemberManager,RoleManager,VoiceStateManagerandPresenceManagercan now be built for one guild.guild.members,guild.roles,guild.voiceStatesandguild.presences(alsoclient.guilds.members(guildId)and friends) hand out those same classes with the guild's ID filled in:cachetakes the entity's ID alone and the methods lose theirguildIdargument.There is no separate set of guild manager classes. The four managers gain an
InGuildtype parameter (falseby default, soclient.membersand existing code are unaffected), an optionalguildIdconstructor argument and aguildIdproperty. On an instance built for a guild, the methods call the client's manager, which keeps the state (pending member requests) and the cache.channel.messagesandthread.membersgain acachekeyed by the ID alone as well.Key changes
client.members.cache.get(client.members.resolveKey(guildId, userId))guild.members.cache.get(userId)client.roles.cache.get(client.roles.resolveKey(guildId, roleId))guild.roles.cache.get(roleId)client.presences.cache.get(client.presences.resolveKey(guildId, userId))guild.presences.cache.get(userId)client.members.kick(guildId, userId)guild.members.kick(userId)client.members.me(guildId)guild.members.me(getter)client.messages.cache.get(client.messages.resolveKey(channelId, messageId))channel.messages.cache.get(messageId)The left-hand forms keep working.
CachedManagertakes an optionalguildIdand then narrowscacheto that guild: a fullCachewhoseget,has,set,delete,getSizeandclearonly see the guild's entries, synchronous when the client's cache is.GuildArgs<InGuild, Args>types the method arguments with or without the leadingguildId;fillGuildIdmakes the listed methods of a guild instance delegate to the client's manager.guild.presences.resolve(value)always reads the manager's guild, whatever guild a member or message belongs to.Things a reviewer may want to look at:
kick(...args: GuildArgs<InGuild, [userId: string, reason?: string]>)). Callers still see the named parameters, but the source is less direct than before.client.members.meis now an instance property holding the function instead of a prototype method. It is called the same way, but a subclass can no longer override it as a method.fillGuildIdare guild-aware. The remaining public members (resolveKey,keyOf,_add, …) still expect the full key and are not meant to be called there.Type of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.