only dispatch an action for self-membership
as everything listens to the dispatcher, dispatching an action can be quite slow, especially when only matched in one listener, and the rest all having to be called to just say "no, thanks". This is especially the case for the RoomMember.membership event being put on the dispatcher, as there can be thousands of these events when the room members are loading. Since the RoomMember.membership action is only used on one place, and only for the syncing user, change it to just that and only dispatch in that case. This saves 100-300ms when setting the OOB members in a big room (7000k members) Maybe later on we can back this by room.getMyMembership() and avoid the listener even...
This commit is contained in:
parent
aa8e998612
commit
9a3717a274
2 changed files with 13 additions and 9 deletions
|
@ -149,9 +149,9 @@ function createRoomTimelineAction(matrixClient, timelineEvent, room, toStartOfTi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a MatrixActions.RoomMember.membership action that represents
|
* Create a MatrixActions.Room.selfMembership action that represents
|
||||||
* a MatrixClient `RoomMember.membership` matrix event, emitted when a
|
* a MatrixClient `RoomMember.membership` matrix event for the syncing user,
|
||||||
* member's membership is updated.
|
* emitted when the member's membership is updated.
|
||||||
*
|
*
|
||||||
* @param {MatrixClient} matrixClient the matrix client.
|
* @param {MatrixClient} matrixClient the matrix client.
|
||||||
* @param {MatrixEvent} membershipEvent the m.room.member event.
|
* @param {MatrixEvent} membershipEvent the m.room.member event.
|
||||||
|
@ -159,8 +159,10 @@ function createRoomTimelineAction(matrixClient, timelineEvent, room, toStartOfTi
|
||||||
* @param {string} oldMembership the member's previous membership.
|
* @param {string} oldMembership the member's previous membership.
|
||||||
* @returns {RoomMembershipAction} an action of type `MatrixActions.RoomMember.membership`.
|
* @returns {RoomMembershipAction} an action of type `MatrixActions.RoomMember.membership`.
|
||||||
*/
|
*/
|
||||||
function createRoomMembershipAction(matrixClient, membershipEvent, member, oldMembership) {
|
function createSelfRoomMembershipAction(matrixClient, membershipEvent, member, oldMembership) {
|
||||||
return { action: 'MatrixActions.RoomMember.membership', member };
|
if (member.userId === matrixClient.getUserId()) {
|
||||||
|
return { action: 'MatrixActions.Room.selfMembership', member };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +204,7 @@ export default {
|
||||||
this._addMatrixClientListener(matrixClient, 'Room', createRoomAction);
|
this._addMatrixClientListener(matrixClient, 'Room', createRoomAction);
|
||||||
this._addMatrixClientListener(matrixClient, 'Room.tags', createRoomTagsAction);
|
this._addMatrixClientListener(matrixClient, 'Room.tags', createRoomTagsAction);
|
||||||
this._addMatrixClientListener(matrixClient, 'Room.timeline', createRoomTimelineAction);
|
this._addMatrixClientListener(matrixClient, 'Room.timeline', createRoomTimelineAction);
|
||||||
this._addMatrixClientListener(matrixClient, 'RoomMember.membership', createRoomMembershipAction);
|
this._addMatrixClientListener(matrixClient, 'RoomMember.membership', createSelfRoomMembershipAction);
|
||||||
this._addMatrixClientListener(matrixClient, 'Event.decrypted', createEventDecryptedAction);
|
this._addMatrixClientListener(matrixClient, 'Event.decrypted', createEventDecryptedAction);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -217,7 +219,10 @@ export default {
|
||||||
*/
|
*/
|
||||||
_addMatrixClientListener(matrixClient, eventName, actionCreator) {
|
_addMatrixClientListener(matrixClient, eventName, actionCreator) {
|
||||||
const listener = (...args) => {
|
const listener = (...args) => {
|
||||||
dis.dispatch(actionCreator(matrixClient, ...args), true);
|
const payload = actionCreator(matrixClient, ...args);
|
||||||
|
if (payload) {
|
||||||
|
dis.dispatch(payload, true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
matrixClient.on(eventName, listener);
|
matrixClient.on(eventName, listener);
|
||||||
this._matrixClientListenersStop.push(() => {
|
this._matrixClientListenersStop.push(() => {
|
||||||
|
|
|
@ -120,8 +120,7 @@ class RoomListStore extends Store {
|
||||||
this._generateRoomLists();
|
this._generateRoomLists();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'MatrixActions.RoomMember.membership': {
|
case 'MatrixActions.Room.selfMembership': {
|
||||||
if (!this._matrixClient || payload.member.userId !== this._matrixClient.credentials.userId) break;
|
|
||||||
this._generateRoomLists();
|
this._generateRoomLists();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue