Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/federation-sdk/src/services/edu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class EduService {

this.logger.debug(`Sending typing notification for room ${roomId}: ${userId} (typing: ${typing}) to all servers in room`);

const servers = await this.stateService.getServersInRoom(roomId);
const uniqueServers = servers.filter((server) => server !== origin);
const servers = await this.stateService.getServerSetInRoom(roomId);
const uniqueServers = Array.from(servers).filter((server) => server !== origin);

await this.federationService.sendEDUToServers([typingEDU], uniqueServers);

Expand All @@ -47,14 +47,16 @@ export class EduService {
this.logger.debug(`Sending presence updates for ${presenceUpdates.length} users to all servers in rooms: ${roomIds.join(', ')}`);
const uniqueServers = new Set<string>();

for await (const roomId of roomIds) {
const servers = await this.stateService.getServersInRoom(roomId);
for (const server of servers) {
if (server !== origin) {
uniqueServers.add(server);
await Promise.all(
roomIds.map(async (roomId) => {
const servers = await this.stateService.getServerSetInRoom(roomId);
for (const server of servers) {
if (server !== origin) {
uniqueServers.add(server);
}
}
}
}
}),
);
Comment on lines +50 to +59
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise.all(roomIds.map(...)) fans out one getServerSetInRoom call per room with no concurrency limit. If roomIds can be large, this can overwhelm the DB/state store and increase tail latency. Consider batching / limiting concurrency (e.g., chunking roomIds, a simple semaphore, or a library like p-limit).

Copilot uses AI. Check for mistakes.

await this.federationService.sendEDUToServers([presenceEDU], Array.from(uniqueServers));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ export class EventAuthorizationService {
return false;
}

const serversInRoom = await this.stateService.getServersInRoom(roomId);
if (serversInRoom.includes(serverName)) {
const serversInRoom = await this.stateService.getServerSetInRoom(roomId);
if (serversInRoom.has(serverName)) {
this.logger.debug(`Server ${serverName} is in room, allowing access`);
return true;
}
Expand Down
5 changes: 0 additions & 5 deletions packages/federation-sdk/src/services/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,6 @@ export class StateService {
return servers;
}

// @deprecated use getServerSetInRoom
async getServersInRoom(roomId: RoomID) {
return Array.from(await this.getServerSetInRoom(roomId));
}

private async _isSameChain(stateIds: StateID[]) {
const stateDocs = await this.stateRepository.findByStateIds(stateIds).toArray();

Expand Down
Loading