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 sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY
): LiveData<PagedList<RoomSummary>> ): 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. * 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) return roomSummaryDataSource.getSortedPagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder)
} }
override fun roomSummariesChangesLive(
queryParams: RoomSummaryQueryParams,
sortOrder: RoomSortOrder): LiveData<List<Unit>> {
return roomSummaryDataSource.getRoomSummariesChangesLive(queryParams, sortOrder)
}
override fun getFilteredPagedRoomSummariesLive( override fun getFilteredPagedRoomSummariesLive(
queryParams: RoomSummaryQueryParams, queryParams: RoomSummaryQueryParams,
pagedListConfig: PagedList.Config, 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( fun getSpaceSummariesLive(
queryParams: SpaceSummaryQueryParams, queryParams: SpaceSummaryQueryParams,
sortOrder: RoomSortOrder = RoomSortOrder.NONE sortOrder: RoomSortOrder = RoomSortOrder.NONE

View file

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

View file

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

View file

@ -75,7 +75,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
private val roomService = session.roomService() private val roomService = session.roomService()
init { init {
roomService.getPagedRoomSummariesLive( roomService.roomSummariesChangesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.spaceFilter = SpaceFilter.OrphanRooms this.spaceFilter = SpaceFilter.OrphanRooms
@ -111,7 +111,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
combine( combine(
spaceStateHandler.getSelectedSpaceFlow().distinctUntilChanged(), spaceStateHandler.getSelectedSpaceFlow().distinctUntilChanged(),
spaceStateHandler.getSelectedSpaceFlow().flatMapLatest { spaceStateHandler.getSelectedSpaceFlow().flatMapLatest {
roomService.getPagedRoomSummariesLive( roomService.roomSummariesChangesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = Membership.activeMemberships() this.memberships = Membership.activeMemberships()
}, sortOrder = RoomSortOrder.NONE }, 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 // XXX there should be a way to refactor this and share it
session.roomService().getPagedRoomSummariesLive( session.roomService().roomSummariesChangesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.spaceFilter = roomsInSpaceFilter() this.spaceFilter = roomsInSpaceFilter()
@ -268,9 +268,7 @@ class SpaceListViewModel @AssistedInject constructor(
combine( combine(
session.flow().liveSpaceSummaries(params), session.flow().liveSpaceSummaries(params),
session.accountDataService() session.flow().liveRoomAccountData(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
.getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER))
.asFlow()
) { spaces, _ -> ) { spaces, _ ->
spaces spaces
}.execute { asyncSpaces -> }.execute { asyncSpaces ->