diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js --- a/keyserver/src/updaters/thread-updaters.js +++ b/keyserver/src/updaters/thread-updaters.js @@ -935,9 +935,7 @@ threadID: string, communityFarcasterChannelTag: string, ): Promise { - const response = await findUserIdentities([viewer.userID]); - - const { farcasterID } = response.identities[viewer.userID]; + const farcasterID = await getUserFarcasterID(viewer.userID); if (!farcasterID) { return null; @@ -961,6 +959,22 @@ return null; } +async function getUserFarcasterID(userID: string): Promise { + const cachedUserIdentity = await redisCache.getUserIdentity(userID); + if (cachedUserIdentity) { + return cachedUserIdentity.farcasterID; + } + + const response = await findUserIdentities([userID]); + const userIdentity = response.identities[userID]; + if (!userIdentity) { + return null; + } + + ignorePromiseRejections(redisCache.setUserIdentity(userID, userIdentity)); + return userIdentity.farcasterID; +} + async function userLeadsChannel( communityFarcasterChannelTag: string, farcasterID: string,