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,26 @@ 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) { + ignorePromiseRejections( + (async () => { + await redisCache.setUserIdentity(userID, userIdentity); + })(), + ); + return userIdentity.farcasterID; + } + + return null; +} + async function userLeadsChannel( communityFarcasterChannelTag: string, farcasterID: string,