perf: server navigation
This commit is contained in:
@@ -111,40 +111,47 @@ export class MessagesSyncEffects {
|
||||
this.actions$.pipe(
|
||||
ofType(RoomsActions.joinRoomSuccess, RoomsActions.viewServerSuccess),
|
||||
withLatestFrom(this.store.select(selectCurrentRoom)),
|
||||
mergeMap(([{ room }, currentRoom]) => {
|
||||
const activeRoom = currentRoom || room;
|
||||
switchMap(([{ room }, currentRoom]) => {
|
||||
const requestedRoomId = room.id;
|
||||
|
||||
if (!activeRoom)
|
||||
return EMPTY;
|
||||
return timer(75).pipe(
|
||||
withLatestFrom(this.store.select(selectCurrentRoom)),
|
||||
switchMap(([, latestCurrentRoom]) => {
|
||||
const activeRoom = latestCurrentRoom ?? currentRoom ?? room;
|
||||
const peers = this.webrtc.getConnectedPeers();
|
||||
|
||||
return from(
|
||||
this.db.getMessages(activeRoom.id, FULL_SYNC_LIMIT, 0)
|
||||
).pipe(
|
||||
tap((messages) => {
|
||||
const count = messages.length;
|
||||
const lastUpdated = getLatestTimestamp(messages);
|
||||
|
||||
for (const pid of this.webrtc.getConnectedPeers()) {
|
||||
try {
|
||||
this.webrtc.sendToPeer(pid, {
|
||||
type: 'chat-sync-summary',
|
||||
roomId: activeRoom.id,
|
||||
count,
|
||||
lastUpdated
|
||||
});
|
||||
|
||||
this.webrtc.sendToPeer(pid, {
|
||||
type: 'chat-inventory-request',
|
||||
roomId: activeRoom.id
|
||||
});
|
||||
} catch (error) {
|
||||
this.debugging.warn('messages', 'Failed to kick off room sync for peer', {
|
||||
error,
|
||||
peerId: pid,
|
||||
roomId: activeRoom.id
|
||||
});
|
||||
}
|
||||
if (!activeRoom || activeRoom.id !== requestedRoomId || peers.length === 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
return from(this.db.getMessages(activeRoom.id, FULL_SYNC_LIMIT, 0)).pipe(
|
||||
tap((messages) => {
|
||||
const count = messages.length;
|
||||
const lastUpdated = getLatestTimestamp(messages);
|
||||
|
||||
for (const pid of peers) {
|
||||
try {
|
||||
this.webrtc.sendToPeer(pid, {
|
||||
type: 'chat-sync-summary',
|
||||
roomId: activeRoom.id,
|
||||
count,
|
||||
lastUpdated
|
||||
});
|
||||
|
||||
this.webrtc.sendToPeer(pid, {
|
||||
type: 'chat-inventory-request',
|
||||
roomId: activeRoom.id
|
||||
});
|
||||
} catch (error) {
|
||||
this.debugging.warn('messages', 'Failed to kick off room sync for peer', {
|
||||
error,
|
||||
peerId: pid,
|
||||
roomId: activeRoom.id
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user