wip: optimizations

This commit is contained in:
2026-05-23 15:28:40 +02:00
parent 5bf506af03
commit 155fe20862
89 changed files with 7431 additions and 392 deletions

View File

@@ -45,6 +45,8 @@ import {
LeaveServerDialogComponent
} from '../../../shared';
const ACTIVATION_DEBOUNCE_MS = 150;
@Component({
selector: 'app-servers-rail',
standalone: true,
@@ -72,6 +74,11 @@ export class ServersRailComponent {
private serverDirectory = inject(ServerDirectoryFacade);
private destroyRef = inject(DestroyRef);
private banLookupRequestVersion = 0;
private bannedLookupUserKey: string | null = null;
private activationRequestVersion = 0;
private activationTimer: ReturnType<typeof window.setTimeout> | null = null;
private joinRequestVersion = 0;
private joinRequestTimer: ReturnType<typeof window.setTimeout> | null = null;
private visibleSavedRoomCache: Room[] = [];
private savedRoomJoinRequests = new Subject<{ room: Room; password?: string }>();
savedRooms = this.store.selectSignal(selectSavedRooms);
@@ -208,6 +215,16 @@ export class ServersRailComponent {
takeUntilDestroyed(this.destroyRef)
)
.subscribe();
this.destroyRef.onDestroy(() => {
if (this.activationTimer) {
window.clearTimeout(this.activationTimer);
}
if (this.joinRequestTimer) {
window.clearTimeout(this.joinRequestTimer);
}
});
}
initial(name?: string): string {
@@ -249,8 +266,8 @@ export class ServersRailComponent {
}
this.optimisticSelectedRoomId.set(targetRoom.id);
this.activateSavedRoom(targetRoom);
this.savedRoomJoinRequests.next({ room: targetRoom });
this.queueSavedRoomActivation(targetRoom);
this.queueSavedRoomJoin(targetRoom);
}
openCall(callId: string): void {
@@ -436,13 +453,36 @@ export class ServersRailComponent {
const requestVersion = ++this.banLookupRequestVersion;
if (!currentUser || rooms.length === 0) {
this.bannedLookupUserKey = null;
this.bannedRoomLookup.set({});
return;
}
const persistedUserId = localStorage.getItem('metoyou_currentUserId');
const userKey = `${currentUser.id}:${currentUser.oderId}:${persistedUserId ?? ''}`;
const roomIds = new Set(rooms.map((room) => room.id));
if (this.bannedLookupUserKey !== userKey) {
this.bannedLookupUserKey = userKey;
this.bannedRoomLookup.set({});
}
const currentLookup = this.bannedRoomLookup();
const nextLookup = Object.fromEntries(
Object.entries(currentLookup).filter(([roomId]) => roomIds.has(roomId))
);
const roomsToLookup = rooms.filter((room) => nextLookup[room.id] === undefined);
if (roomsToLookup.length === 0) {
if (Object.keys(nextLookup).length !== Object.keys(currentLookup).length) {
this.bannedRoomLookup.set(nextLookup);
}
return;
}
const entries = await Promise.all(
rooms.map(async (room) => {
roomsToLookup.map(async (room) => {
const bans = await this.db.getBansForRoom(room.id);
return [room.id, hasRoomBanForUser(bans, currentUser, persistedUserId)] as const;
@@ -453,7 +493,10 @@ export class ServersRailComponent {
return;
}
this.bannedRoomLookup.set(Object.fromEntries(entries));
this.bannedRoomLookup.set({
...nextLookup,
...Object.fromEntries(entries)
});
}
private prepareVoiceContext(room: Room): void {
@@ -473,6 +516,40 @@ export class ServersRailComponent {
this.store.dispatch(RoomsActions.viewServer({ room, skipBanCheck: true }));
}
private queueSavedRoomActivation(room: Room): void {
const requestVersion = ++this.activationRequestVersion;
if (this.activationTimer) {
window.clearTimeout(this.activationTimer);
}
this.activationTimer = window.setTimeout(() => {
if (requestVersion !== this.activationRequestVersion) {
return;
}
this.activationTimer = null;
this.activateSavedRoom(room);
}, ACTIVATION_DEBOUNCE_MS);
}
private queueSavedRoomJoin(room: Room): void {
const requestVersion = ++this.joinRequestVersion;
if (this.joinRequestTimer) {
window.clearTimeout(this.joinRequestTimer);
}
this.joinRequestTimer = window.setTimeout(() => {
if (requestVersion !== this.joinRequestVersion) {
return;
}
this.joinRequestTimer = null;
this.savedRoomJoinRequests.next({ room });
}, ACTIVATION_DEBOUNCE_MS);
}
private requestJoinInBackground(room: Room, password?: string) {
const currentUserId = localStorage.getItem('metoyou_currentUserId');
const currentUser = this.currentUser();