Stop re-attempting /joined_members on rooms we can't read

Reddit's homeserver returns 404 from /_matrix/client/v3/rooms/{id}/joined_members
for rooms we've left, been kicked from, or never fully joined — which is
roughly every chat that wasn't accepted by the recipient. The previous
enrichUsernames pass retried these on every delta sync, flooding the
dashboard log with debug-level 404s. Track failures in an in-memory
unresolvable set so each room is tried at most once per process.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jjbruntonandClaude Opus 4.7 committed 2026-05-22 23:06:33 +01:00
1 parent ad5c63fc50
commit 1df7b680ee
1 file changed
+11
+11
View File
@@ -104,6 +104,8 @@ export class ChatService {
private cache: ChatCache;
private queue: Promise<unknown> = Promise.resolve();
private readonly t2ToUsername = new Map<string, string>();
/** Rooms whose /joined_members lookup has already failed — don't retry. */
private readonly unresolvableRooms = new Set<string>();
private syncingKind: 'full' | 'delta' | null = null;
private progress: SyncProgress | null = null;
private progressListener: SyncProgressListener | null = null;
@@ -1006,6 +1008,7 @@ export class ChatService {
const roomT2: Map<string, string> = new Map(); // roomId -> bare t2 id
for (const chat of this.cache.get()) {
if (!chat.roomId) continue;
if (this.unresolvableRooms.has(chat.roomId)) continue;
const needsLookup =
!chat.username ||
chat.username === 'unknown' ||
@@ -1023,8 +1026,16 @@ export class ChatService {
if (!chat.roomName || chat.roomName === 'unknown' || chat.roomName.startsWith('@')) {
chat.roomName = chat.username;
}
} else {
// No t2-shaped member in the room (probably empty or only us
// after the other party left). Don't keep retrying every sync.
this.unresolvableRooms.add(chat.roomId);
}
} catch (err) {
// 404/403 means we can't read membership for this room (left, kicked,
// or never fully joined). Cache the failure so the next delta doesn't
// spam the homeserver — and the log — with the same lookup.
this.unresolvableRooms.add(chat.roomId);
this.logger.debug(`[chat] joined_members lookup failed for ${chat.roomId}:`, err);
}
}