Browse Source

Performance : rename RustRoomObjects to RustRoomReferences

pull/3186/head
ganfra 2 months ago
parent
commit
7fab94fdd7
  1. 22
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustRoomFactory.kt

22
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustRoomFactory.kt

@ -62,12 +62,12 @@ class RustRoomFactory(
private val mutex = Mutex() private val mutex = Mutex()
private var isDestroyed: Boolean = false private var isDestroyed: Boolean = false
private data class RustRoomObjects( private data class RustRoomReferences(
val roomListItem: RoomListItem, val roomListItem: RoomListItem,
val fullRoom: Room, val fullRoom: Room,
) )
private val cache = lruCache<RoomId, RustRoomObjects>( private val cache = lruCache<RoomId, RustRoomReferences>(
maxSize = CACHE_SIZE, maxSize = CACHE_SIZE,
onEntryRemoved = { evicted, roomId, oldRoom, _ -> onEntryRemoved = { evicted, roomId, oldRoom, _ ->
Timber.d("On room removed from cache: $roomId, evicted: $evicted") Timber.d("On room removed from cache: $roomId, evicted: $evicted")
@ -104,22 +104,22 @@ class RustRoomFactory(
Timber.d("Room factory is destroyed, returning null for $roomId") Timber.d("Room factory is destroyed, returning null for $roomId")
return@withContext null return@withContext null
} }
var roomObjects: RustRoomObjects? = getRoomObjects(roomId) var roomReferences: RustRoomReferences? = getRoomReferences(roomId)
if (roomObjects == null) { if (roomReferences == null) {
// ... otherwise, lets wait for the SS to load all rooms and check again. // ... otherwise, lets wait for the SS to load all rooms and check again.
roomListService.allRooms.awaitLoaded() roomListService.allRooms.awaitLoaded()
roomObjects = getRoomObjects(roomId) roomReferences = getRoomReferences(roomId)
} }
if (roomObjects == null) { if (roomReferences == null) {
Timber.d("No room found for $roomId, returning null") Timber.d("No room found for $roomId, returning null")
return@withContext null return@withContext null
} }
val liveTimeline = roomObjects.fullRoom.timeline() val liveTimeline = roomReferences.fullRoom.timeline()
RustMatrixRoom( RustMatrixRoom(
sessionId = sessionId, sessionId = sessionId,
isKeyBackupEnabled = isKeyBackupEnabled(), isKeyBackupEnabled = isKeyBackupEnabled(),
roomListItem = roomObjects.roomListItem, roomListItem = roomReferences.roomListItem,
innerRoom = roomObjects.fullRoom, innerRoom = roomReferences.fullRoom,
innerTimeline = liveTimeline, innerTimeline = liveTimeline,
sessionCoroutineScope = sessionCoroutineScope, sessionCoroutineScope = sessionCoroutineScope,
notificationSettingsService = notificationSettingsService, notificationSettingsService = notificationSettingsService,
@ -133,7 +133,7 @@ class RustRoomFactory(
} }
} }
private suspend fun getRoomObjects(roomId: RoomId): RustRoomObjects? { private suspend fun getRoomReferences(roomId: RoomId): RustRoomReferences? {
cache[roomId]?.let { cache[roomId]?.let {
Timber.d("Room found in cache for $roomId") Timber.d("Room found in cache for $roomId")
return it return it
@ -150,7 +150,7 @@ class RustRoomFactory(
return null return null
} }
Timber.d("Got full room with timeline for $roomId") Timber.d("Got full room with timeline for $roomId")
return RustRoomObjects( return RustRoomReferences(
roomListItem = roomListItem, roomListItem = roomListItem,
fullRoom = fullRoom, fullRoom = fullRoom,
).also { ).also {

Loading…
Cancel
Save