Skip to content

Commit

Permalink
Store both user and member data on cache for member operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Galarzaa90 committed Aug 11, 2024
1 parent eb98ccc commit b4fff47
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/src/commonMain/kotlin/supplier/StoreEntitySupplier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public class StoreEntitySupplier(

}

override suspend fun getMemberOrNull(guildId: Snowflake, userId: Snowflake): Member? {
return storeAndReturn(supplier.getMemberOrNull(guildId, userId)) { it.memberData }
}
override suspend fun getMemberOrNull(guildId: Snowflake, userId: Snowflake): Member? =
supplier.getMemberOrNull(guildId, userId)?.also { member ->
cache.put(member.data)
cache.put(member.memberData)
}

override suspend fun getMessageOrNull(channelId: Snowflake, messageId: Snowflake): Message? {
return storeAndReturn(supplier.getMessageOrNull(channelId, messageId)) { it.data }
Expand Down Expand Up @@ -104,9 +106,11 @@ public class StoreEntitySupplier(
return storeOnEach(supplier.getGuildBans(guildId, limit)) { it.data }
}

override fun getGuildMembers(guildId: Snowflake, limit: Int?): Flow<Member> {
return storeOnEach(supplier.getGuildMembers(guildId, limit)) { it.memberData }
}
override fun getGuildMembers(guildId: Snowflake, limit: Int?): Flow<Member> =
supplier.getGuildMembers(guildId, limit).onEach { member ->
cache.put(member.data)
cache.put(member.memberData)
}

override fun getGuildVoiceRegions(guildId: Snowflake): Flow<Region> {
return storeOnEach(supplier.getGuildVoiceRegions(guildId)) { it.data }
Expand Down

0 comments on commit b4fff47

Please sign in to comment.