Merge pull request #4961 from vector-im/gil/4898_fix_performance_issues_with_spaces

Fix performance issues with Spaces on very large accounts #4898
This commit is contained in:
Gil Eluard 2021-10-07 13:15:05 +02:00 committed by GitHub
commit 5486d8ed7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 5 deletions

View file

@ -80,7 +80,7 @@ class SpaceDetailViewModel: SpaceDetailViewModelType {
self.update(viewState: .loaded(parameters))
self.update(viewState: .loading)
space.room.state { state in
space.room?.state { state in
let joinRule = state?.joinRule
let membersCount = summary.membersCount.members

View file

@ -53,6 +53,8 @@ final class SpaceListViewModel: SpaceListViewModelType {
self.userSessionsService = userSessionsService
NotificationCenter.default.addObserver(self, selector: #selector(self.sessionDidSync(notification:)), name: MXSpaceService.didBuildSpaceGraph, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.counterDidUpdateNotificationCount(notification:)), name: MXSpaceNotificationCounter.didUpdateNotificationCount, object: nil)
}
@ -122,6 +124,10 @@ final class SpaceListViewModel: SpaceListViewModelType {
loadData()
}
@objc private func counterDidUpdateNotificationCount(notification: Notification) {
loadData()
}
private func loadData() {
guard let session = self.userSessionsService.mainUserSession?.matrixSession else {
return

View file

@ -76,12 +76,12 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
}
private func leaveSpace() {
guard let space = self.session.spaceService.getSpace(withId: self.spaceId), let displayName = space.summary?.displayname else {
guard let room = self.session.room(withRoomId: self.spaceId), let displayName = room.summary?.displayname else {
return
}
var isAdmin = false
if let roomState = space.room.dangerousSyncState, let powerLevels = roomState.powerLevels {
if let roomState = room.dangerousSyncState, let powerLevels = roomState.powerLevels {
let powerLevel = powerLevels.powerLevelOfUser(withUserID: self.session.myUserId)
let roomPowerLevel = RoomPowerLevelHelper.roomPowerLevel(from: powerLevel)
isAdmin = roomPowerLevel == .admin
@ -156,7 +156,7 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
}
private func leaveSpace(_ space: MXSpace) {
space.room.leave(completion: { [weak self] response in
space.room?.leave(completion: { [weak self] response in
guard let self = self else {
return
}

View file

@ -64,6 +64,8 @@
// Custom title view of the navigation bar
MainTitleView *titleView;
id spaceNotificationCounterDidUpdateNotificationCountObserver;
}
@property(nonatomic,getter=isHidden) BOOL hidden;
@ -122,7 +124,7 @@
childViewControllers = [NSMutableArray array];
MXWeakify(self);
[[NSNotificationCenter defaultCenter] addObserverForName:MXSpaceService.didBuildSpaceGraph object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
spaceNotificationCounterDidUpdateNotificationCountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:MXSpaceNotificationCounter.didUpdateNotificationCount object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
MXStrongifyAndReturnIfNil(self);
[self updateSideMenuNotifcationIcon];
}];
@ -272,6 +274,12 @@
kThemeServiceDidChangeThemeNotificationObserver = nil;
}
if (spaceNotificationCounterDidUpdateNotificationCountObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:spaceNotificationCounterDidUpdateNotificationCountObserver];
spaceNotificationCounterDidUpdateNotificationCountObserver = nil;
}
childViewControllers = nil;
}

1
changelog.d/4898.bugfix Normal file
View file

@ -0,0 +1 @@
MasterTabBarController: Listen to `MXSpaceNotificationCounter` to update the notification badge