K
Kord2mo ago
Galarzaa

`getMember` not writing to Member cache?

I have a task that is periodically doing some checks to update some content. This goes guild by guild (in the guilds that use the feature). At some point I get the channel entity, and then I get the permissions for the bot. For this I use kordex's GuildChannel.botHasPermissions, and its first step is calling GuildBehaviour.getMember with the bot's snowflake. The problem is that this is doing a REST call every single time and therefore greatly slowing my process, not to mention the possibl rate limit implications. I'm using EntitySupplyStrategy.cacheWithCachingRestFallback. I have been browing through Kord's source and something I notice is: On the handler for GuildMemberUpdate, there's this:
val new = Member(MemberData.from(this), userData, kord)
kord.cache.put(new.memberData)
val new = Member(MemberData.from(this), userData, kord)
kord.cache.put(new.memberData)
Where memberData is of type MemberData. On StoreEntitySupplier, we have the following:
override suspend fun getMemberOrNull(guildId: Snowflake, userId: Snowflake): Member? {
return storeAndReturn(supplier.getMemberOrNull(guildId, userId)) { it.data }
}
override suspend fun getMemberOrNull(guildId: Snowflake, userId: Snowflake): Member? {
return storeAndReturn(supplier.getMemberOrNull(guildId, userId)) { it.data }
}
Where it.data is of type UserData. Doesn't that mean that this entity is being saved to the User cache, and therefore not available when trying to get it from the Member cache? I see that CacheEntitySupplier.getMemberOrNull is using both caches in order to create the full Member object, so the cache is always returning null. Is this intended?
No description
6 Replies
Galarzaa
Galarzaa2mo ago
Same case for getGuildMembers
override fun getGuildMembers(guildId: Snowflake, limit: Int?): Flow<Member> {
return storeOnEach(supplier.getGuildMembers(guildId, limit)) { it.data } // this is UserData
}
override fun getGuildMembers(guildId: Snowflake, limit: Int?): Flow<Member> {
return storeOnEach(supplier.getGuildMembers(guildId, limit)) { it.data } // this is UserData
}
LustigerLurch
LustigerLurch2mo ago
hm, that indeed seems like a bug
Galarzaa
Galarzaa2mo ago
I'll try submitting a PR for this if I have time
LustigerLurch
LustigerLurch2mo ago
thanks :)
Galarzaa
Galarzaa2mo ago
GitHub
Fix getMemberOrNull and getGuildMembers caching user data instead o...
As reported in Discord, these calls are storing the results to the user cache, so subsequent calls would not find them from cache. When using cacheWithCachingRestFallback, this results in REST call...
LustigerLurch
LustigerLurch2mo ago
nice :D
Want results from more Discord servers?
Add your server