Repository navigation
feat: resolve the guild of gateway structures from the cache - #103
Conversation
◈ PR LensPR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z. |
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline, and a coverage note below.
Reviewed changes
Reviewed the full diff: every guild-scoped structure in plugin-gateway (channels/threads, GuildMember, Role, Message, GuildEmoji, Sticker, GuildInvite) gains a cached guild getter plus (mostly) a fetchGuild() REST fallback, and Message gains a cached channel getter.
kRelationssymbol —Structurereplaces the old one-private-field-per-class pattern with a single exportedkRelationsslot, needed because mixin getters (GuildChannelMixin) can't see a class's private fields;kClonenow shallow-copies it anddropRelations()invalidates named relations on fresher patch data.CachedManager.cachedGuild()— new cache-only helper (this.client.guilds.get(guildId) ?? null), used by every touched manager'shydrate()alongside existing relations viaPromise.all.ChannelManager/ThreadManager— derive the guild ID via achannelGuildId()helper that accounts forGUILD_CREATE's embedded channels not carryingguild_idnatively (verified againstplugin-cache'shydrateGuildCreate, which synthesizes it).MessageManager— resolveschannelviaclient.channels.get(), which already falls back to the thread cache, so messages in threads resolve correctly.- Tests —
tests/cached-manager.test.tsgains coverage for channel/role/message/memberguildresolution, an uncached/hand-built →nullcase, and clone-retains-relations.
I traced the trickier claims by hand (GUILD_CREATE's synthesized guild_id, thread fallback in ChannelManager.get, member guild_id backfill in fetchRaw, mixin type-narrowing of kRelations) and didn't find a correctness issue in any of them — the pattern is applied consistently across all seven structures.
ℹ️ Nitpicks
- New tests cover
guildresolution for channels, roles, messages, and members, but notGuildEmoji,Sticker, orGuildInvite— they follow the exact samecachedGuild()pattern, so risk is low, but it's a gap worth closing before the pattern is copied elsewhere.
Claude Sonnet | 𝕏
@wolfstar/plugin-api
@wolfstar/plugin-cache
@wolfstar/plugin-gateway
@wolfstar/plugin-i18next
@wolfstar/plugin-logger
@wolfstar/plugin-subcommands-advanced
commit: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed commit 8c9b9ec ("fix(plugin-gateway): type-check relation names and cover asset guilds"), which addresses both points from the prior Pullfrog review of b33b12f.
- Tightened
dropRelations's parameter type —Structure.dropRelations(...names: string[])is nowdropRelations(...names: (keyof this[typeof kRelations] & string)[]), so a typo'd or renamed relation key now fails to compile instead of silently no-op'ing at runtime. - Widened
[kRelations]fromprotectedtopublic— required by the above (the basedropRelationsmethod needs to referencethis[typeof kRelations]in a type position across all narrowed subclasses); applied consistently toStructureand all 7 narrowing subclasses (BaseInvite,Channel,GuildEmoji,GuildMember,Message,Role,Sticker), and documented with an@internalJSDoc explaining why. - Added missing test coverage — a new
describe("guild relations of guild assets", ...)block intests/cached-manager.test.tsexercisesGuildEmoji/Sticker/GuildInvite'sguildresolution viaclient.guilds.emojis/stickers/invites(guildId).fetch(...), closing the gap the prior review flagged.
I traced the [kRelations] widening for misuse risk (grepped every read/write site) and found none outside the intended getter/constructor/kClone/dropRelations pattern — the wider accessibility is a real but currently-unexploited surface expansion, reasonable given the alternative (readonly isn't viable, since both dropRelations and [kClone] mutate the field outside the constructor). I also rebuilt @wolfstar/plugin-cache and ran tsc --noEmit (clean) plus the full cached-manager.test.ts suite (12/12 passing, including the 2 new tests) to confirm the generic-constraint change compiles and the new tests genuinely exercise the emoji/sticker/invite paths rather than asserting tautologies.
The prior review's one open thread (Structure.ts:97-108, untyped dropRelations names) is addressed and resolved.
Claude Sonnet | 𝕏
8c9b9ec to
c6beff4
Compare
c6beff4 to
113d4c4
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|
113d4c4 to
6684158
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|

Stacked on #102.
🔗 Linked issue
Related to #54.
🧭 Context
#102 resolves authors and users from the cache. discord.js also resolves a structure's guild:
channel.guild,member.guild,role.guild,message.guildand so on are all the cachedGuild. Here, guild structures only hadguildId, andfetchGuild()existed only onMessage.📚 Description
Every guild structure now has a
guildgetter that returns the cached guild. That covers channels and threads, members, roles, messages, emojis, stickers and invites. Messages also getchannel, the cached channel. Managers resolve both inhydrate, so they come for free withget,fetch,_addand the gateway events. The getter isnullwhen the guild isn't cached or the structure was built by hand.fetchGuild()is now on every guild structure for when you need the guild regardless.GuildInvite#guildmatches discord.js: the cachedGuildwhen there is one, else the partialInviteGuildfrom the API.The relations from #102 used one private field per class. That can't work for channels, since their getters live in mixins that can't see a class's private fields. So
Structurenow keeps every relation under one exportedkRelationssymbol:declare protected [kRelations]: MessageRelations);kClonecopies them, so a clone keeps its guild;dropRelations()forgets a relation when a patch carries fresher data for it, e.g.message.edit()returning a new author.One cost to know: resolving
guildis one more cache read per structure.hydrateruns all of a structure's reads in parallel, but listing 1000 members still reads the same guild 1000 times. On Redis that's worth batching later, e.g. per-call memoization in list methods.Key changes
StructurekRelationsslot, constructorrelationsargument,kClonekeeps relations,dropRelationsguildGuildChannelMixin),GuildMember,Role,Message,GuildEmoji,Sticker,GuildInvitefetchGuild()GuildMember,Role,GuildEmoji,Stickerand guild channelsMessage#channelhydrateresolves the guild through the newcachedGuild()helperType of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.