diff --git a/keyserver/src/shared/state-sync/entries-state-sync-spec.js b/keyserver/src/shared/state-sync/entries-state-sync-spec.js --- a/keyserver/src/shared/state-sync/entries-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/entries-state-sync-spec.js @@ -24,5 +24,6 @@ return serverEntryInfosObject(entriesResult.rawEntryInfos); }, hashKey: 'entryInfos', + innerHashKey: 'entryInfo', }, ); diff --git a/keyserver/src/shared/state-sync/state-sync-spec.js b/keyserver/src/shared/state-sync/state-sync-spec.js --- a/keyserver/src/shared/state-sync/state-sync-spec.js +++ b/keyserver/src/shared/state-sync/state-sync-spec.js @@ -11,4 +11,5 @@ ids?: $ReadOnlySet, ) => Promise, +hashKey: string, + +innerHashKey?: string, }; diff --git a/keyserver/src/shared/state-sync/threads-state-sync-spec.js b/keyserver/src/shared/state-sync/threads-state-sync-spec.js --- a/keyserver/src/shared/state-sync/threads-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/threads-state-sync-spec.js @@ -21,4 +21,5 @@ return result.threadInfos; }, hashKey: 'threadInfos', + innerHashKey: 'threadInfo', }); diff --git a/keyserver/src/shared/state-sync/users-state-sync-spec.js b/keyserver/src/shared/state-sync/users-state-sync-spec.js --- a/keyserver/src/shared/state-sync/users-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/users-state-sync-spec.js @@ -20,4 +20,5 @@ return fetchKnownUserInfos(viewer); }, hashKey: 'userInfos', + innerHashKey: 'userInfo', }); diff --git a/keyserver/src/socket/session-utils.js b/keyserver/src/socket/session-utils.js --- a/keyserver/src/socket/session-utils.js +++ b/keyserver/src/socket/session-utils.js @@ -409,19 +409,15 @@ invalidKeys.has(spec.hashKey), ]), ); - const threadIDsToFetch = new Set(), - entryIDsToFetch = new Set(), - userIDsToFetch = new Set(); + const idsToFetch = Object.fromEntries( + values(serverStateSyncSpecs) + .filter(spec => spec.innerHashKey) + .map(spec => [spec.innerHashKey, new Set()]), + ); for (const key of invalidKeys) { - if (key.startsWith('threadInfo|')) { - const [, threadID] = key.split('|'); - threadIDsToFetch.add(threadID); - } else if (key.startsWith('entryInfo|')) { - const [, entryID] = key.split('|'); - entryIDsToFetch.add(entryID); - } else if (key.startsWith('userInfo|')) { - const [, userID] = key.split('|'); - userIDsToFetch.add(userID); + const [innerHashKey, id] = key.split('|'); + if (innerHashKey && id) { + idsToFetch[innerHashKey]?.add(id); } } @@ -431,11 +427,11 @@ viewer, query, ); - } else if (threadIDsToFetch.size > 0) { + } else if (idsToFetch[serverStateSyncSpecs.threads.innerHashKey]?.size > 0) { fetchPromises.threadInfos = serverStateSyncSpecs.threads.fetch( viewer, query, - threadIDsToFetch, + idsToFetch[serverStateSyncSpecs.threads.innerHashKey], ); } if (shouldFetchAll[serverStateSyncSpecs.entries.hashKey]) { @@ -443,20 +439,20 @@ viewer, query, ); - } else if (entryIDsToFetch.size > 0) { + } else if (idsToFetch[serverStateSyncSpecs.entries.innerHashKey]?.size > 0) { fetchPromises.entryInfos = serverStateSyncSpecs.entries.fetch( viewer, query, - entryIDsToFetch, + idsToFetch[serverStateSyncSpecs.entries.innerHashKey], ); } if (shouldFetchAll[serverStateSyncSpecs.users.hashKey]) { fetchPromises.userInfos = serverStateSyncSpecs.users.fetch(viewer, query); - } else if (userIDsToFetch.size > 0) { + } else if (idsToFetch[serverStateSyncSpecs.users.innerHashKey]?.size > 0) { fetchPromises.userInfos = serverStateSyncSpecs.users.fetch( viewer, query, - userIDsToFetch, + idsToFetch[serverStateSyncSpecs.users.innerHashKey], ); } if (shouldFetchAll[serverStateSyncSpecs.currentUser.hashKey]) {