Better Ram mgmt and offload from main

This commit is contained in:
valere 2023-01-27 17:11:20 +01:00
parent 2a5768dd60
commit 8593f2330f
7 changed files with 44 additions and 12 deletions

View file

@ -244,6 +244,15 @@ interface RoomService {
sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY
): LiveData<PagedList<RoomSummary>>
/**
* Only notifies when this query has changes.
* It doesn't load any items in memory
*/
fun roomSummariesChangesLive(
queryParams: RoomSummaryQueryParams,
sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY
): LiveData<List<Unit>>
/**
* Get's a live paged list from a filter that can be dynamically updated.
*

View file

@ -154,6 +154,12 @@ internal class DefaultRoomService @Inject constructor(
return roomSummaryDataSource.getSortedPagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder)
}
override fun roomSummariesChangesLive(
queryParams: RoomSummaryQueryParams,
sortOrder: RoomSortOrder): LiveData<List<Unit>> {
return roomSummaryDataSource.getRoomSummariesChangesLive(queryParams, sortOrder)
}
override fun getFilteredPagedRoomSummariesLive(
queryParams: RoomSummaryQueryParams,
pagedListConfig: PagedList.Config,

View file

@ -130,6 +130,18 @@ internal class RoomSummaryDataSource @Inject constructor(
)
}
fun getRoomSummariesChangesLive(
queryParams: RoomSummaryQueryParams,
sortOrder: RoomSortOrder = RoomSortOrder.NONE
): LiveData<List<Unit>> {
return monarchy.findAllMappedWithChanges(
{
roomSummariesQuery(it, queryParams).process(sortOrder)
},
{ emptyList<Unit>() }
)
}
fun getSpaceSummariesLive(
queryParams: SpaceSummaryQueryParams,
sortOrder: RoomSortOrder = RoomSortOrder.NONE

View file

@ -192,10 +192,13 @@ internal class RustCryptoService @Inject constructor(
}
override suspend fun fetchDevicesList(): List<DeviceInfo> {
val devicesList = tryOrNull {
getDevicesTask.execute(Unit).devices
}.orEmpty()
cryptoStore.saveMyDevicesInfo(devicesList)
val devicesList: List<DeviceInfo>
withContext(coroutineDispatchers.io) {
devicesList = tryOrNull {
getDevicesTask.execute(Unit).devices
}.orEmpty()
cryptoStore.saveMyDevicesInfo(devicesList)
}
return devicesList
}
@ -239,7 +242,7 @@ internal class RustCryptoService @Inject constructor(
*/
override fun start() {
internalStart()
cryptoCoroutineScope.launch {
cryptoCoroutineScope.launch(coroutineDispatchers.io) {
cryptoStore.open()
// Just update
fetchDevicesList()

View file

@ -25,6 +25,7 @@ import dagger.assisted.AssistedInject
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.dispatchers.CoroutineDispatchers
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
import im.vector.app.core.pushers.PushersManager
@ -92,6 +93,7 @@ class HomeActivityViewModel @AssistedInject constructor(
private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase,
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase,
private val coroutineDispatchers: CoroutineDispatchers
) : VectorViewModel<HomeActivityViewState, HomeActivityViewActions, HomeActivityViewEvents>(initialState) {
@AssistedFactory
@ -116,7 +118,9 @@ class HomeActivityViewModel @AssistedInject constructor(
if (isInitialized) return
isInitialized = true
registerUnifiedPushIfNeeded()
cleanupFiles()
viewModelScope.launch(coroutineDispatchers.io) {
cleanupFiles()
}
observeInitialSync()
checkSessionPushIsOn()
observeCrossSigningReset()

View file

@ -75,7 +75,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
private val roomService = session.roomService()
init {
roomService.getPagedRoomSummariesLive(
roomService.roomSummariesChangesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.spaceFilter = SpaceFilter.OrphanRooms
@ -111,7 +111,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
combine(
spaceStateHandler.getSelectedSpaceFlow().distinctUntilChanged(),
spaceStateHandler.getSelectedSpaceFlow().flatMapLatest {
roomService.getPagedRoomSummariesLive(
roomService.roomSummariesChangesLive(
roomSummaryQueryParams {
this.memberships = Membership.activeMemberships()
}, sortOrder = RoomSortOrder.NONE

View file

@ -93,7 +93,7 @@ class SpaceListViewModel @AssistedInject constructor(
}
// XXX there should be a way to refactor this and share it
session.roomService().getPagedRoomSummariesLive(
session.roomService().roomSummariesChangesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.spaceFilter = roomsInSpaceFilter()
@ -268,9 +268,7 @@ class SpaceListViewModel @AssistedInject constructor(
combine(
session.flow().liveSpaceSummaries(params),
session.accountDataService()
.getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
.asFlow()
session.flow().liveRoomAccountData(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
) { spaces, _ ->
spaces
}.execute { asyncSpaces ->