diff --git a/matrix/services/room/src/main/kotlin/app/dapk/st/matrix/room/internal/RoomMembers.kt b/matrix/services/room/src/main/kotlin/app/dapk/st/matrix/room/internal/RoomMembers.kt index 9c7a03b..d9004d0 100644 --- a/matrix/services/room/src/main/kotlin/app/dapk/st/matrix/room/internal/RoomMembers.kt +++ b/matrix/services/room/src/main/kotlin/app/dapk/st/matrix/room/internal/RoomMembers.kt @@ -31,6 +31,7 @@ class RoomMembers(private val memberStore: MemberStore, private val membersCache missingIds.isNotEmpty() -> { (memberStore.query(roomId, missingIds).also { membersCache.insert(roomId, it) } + cachedMembers) } + else -> cachedMembers } } @@ -44,14 +45,17 @@ class RoomMembers(private val memberStore: MemberStore, private val membersCache } } +private const val ROOMS_TO_CACHE_MEMBERS_FOR_SIZE = 12 +private const val MEMBERS_TO_CACHE_PER_ROOM = 25 + class RoomMembersCache { - private val cache = LRUCache>(maxSize = 12) + private val cache = LRUCache>(maxSize = ROOMS_TO_CACHE_MEMBERS_FOR_SIZE) fun room(roomId: RoomId) = cache.get(roomId) fun insert(roomId: RoomId, members: List) { - val map = cache.getOrPut(roomId) { LRUCache(maxSize = 25) } + val map = cache.getOrPut(roomId) { LRUCache(maxSize = MEMBERS_TO_CACHE_PER_ROOM) } members.forEach { map.put(it.id, it) } } }