diff --git a/keyserver/src/creators/farcaster-channel-tag-creator.js b/keyserver/src/creators/farcaster-channel-tag-creator.js --- a/keyserver/src/creators/farcaster-channel-tag-creator.js +++ b/keyserver/src/creators/farcaster-channel-tag-creator.js @@ -32,7 +32,7 @@ import { Viewer } from '../session/viewer.js'; import { updateThread } from '../updaters/thread-updaters.js'; import { thisKeyserverID } from '../user/identity.js'; -import { neynarClient } from '../utils/fc-cache.js'; +import { fcCache } from '../utils/fc-cache.js'; import { getAndAssertKeyserverURLFacts } from '../utils/urls.js'; async function createOrUpdateFarcasterChannelTag( @@ -137,10 +137,10 @@ } const neynarChannelDescriptionPromise = (async () => { - if (!neynarClient) { + if (!fcCache) { return ''; } - const channelInfo = await neynarClient?.fetchFarcasterChannelByID( + const channelInfo = await fcCache?.getFarcasterChannelForChannelID( request.farcasterChannelID, ); return channelInfo?.description ?? ''; diff --git a/keyserver/src/responders/farcaster-webhook-responders.js b/keyserver/src/responders/farcaster-webhook-responders.js --- a/keyserver/src/responders/farcaster-webhook-responders.js +++ b/keyserver/src/responders/farcaster-webhook-responders.js @@ -35,7 +35,7 @@ import { thisKeyserverAdmin, thisKeyserverID } from '../user/identity.js'; import { getFarcasterBotConfig } from '../utils/farcaster-bot.js'; import { getVerifiedUserIDForFID } from '../utils/farcaster-utils.js'; -import { neynarClient } from '../utils/fc-cache.js'; +import { neynarClient, fcCache } from '../utils/fc-cache.js'; import { getNeynarConfig } from '../utils/neynar-utils.js'; const taggedCommFarcasterInputValidator = @@ -131,7 +131,7 @@ const keyserverAdminPromise = thisKeyserverAdmin(); const neynarChannel = - await neynarClient?.fetchFarcasterChannelByID(channelID); + await fcCache?.getFarcasterChannelForChannelID(channelID); if (!neynarChannel) { throw new ServerError('channel_not_found'); } 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 @@ -67,7 +67,7 @@ verifyUserOrCookieIDs, } from '../fetchers/user-fetchers.js'; import type { Viewer } from '../session/viewer.js'; -import { neynarClient } from '../utils/fc-cache.js'; +import { neynarClient, fcCache } from '../utils/fc-cache.js'; import { findUserIdentities } from '../utils/identity-utils.js'; import { redisCache } from '../utils/redis-cache.js'; import RelationshipChangeset from '../utils/relationship-changeset.js'; @@ -1001,7 +1001,7 @@ })(), ); - const channelInfo = await neynarClient?.fetchFarcasterChannelByID( + const channelInfo = await fcCache?.getFarcasterChannelForChannelID( communityFarcasterChannelTag, ); if (channelInfo) { diff --git a/keyserver/src/utils/fc-cache.js b/keyserver/src/utils/fc-cache.js --- a/keyserver/src/utils/fc-cache.js +++ b/keyserver/src/utils/fc-cache.js @@ -10,8 +10,9 @@ import { getNeynarConfig } from './neynar-utils.js'; -let getFCNames: ?GetFCNames; let neynarClient: ?NeynarClient; +let fcCache: ?FCCache; +let getFCNames: ?GetFCNames; async function initFCCache() { const neynarSecret = await getNeynarConfig(); @@ -20,9 +21,10 @@ return; } neynarClient = new NeynarClient(neynarKey); - const fcCache = new FCCache(neynarClient); + const newFCCache = new FCCache(neynarClient); + fcCache = newFCCache; getFCNames = (users: $ReadOnlyArray): Promise => - baseGetFCNames(fcCache, users); + baseGetFCNames(newFCCache, users); } -export { initFCCache, getFCNames, neynarClient }; +export { initFCCache, neynarClient, fcCache, getFCNames }; diff --git a/native/community-settings/tag-farcaster-channel/tag-farcaster-channel-by-name.react.js b/native/community-settings/tag-farcaster-channel/tag-farcaster-channel-by-name.react.js --- a/native/community-settings/tag-farcaster-channel/tag-farcaster-channel-by-name.react.js +++ b/native/community-settings/tag-farcaster-channel/tag-farcaster-channel-by-name.react.js @@ -49,7 +49,7 @@ const onPressTagChannel = React.useCallback(async () => { const channelInfo = - await neynarClientContext.client.fetchFarcasterChannelByID( + await neynarClientContext.fcCache.getFarcasterChannelForChannelID( channelSelectionText, ); @@ -59,7 +59,7 @@ } createTag(channelInfo.id); - }, [channelSelectionText, createTag, neynarClientContext.client]); + }, [channelSelectionText, createTag, neynarClientContext.fcCache]); const errorMessage = React.useMemo(() => { if (!error) { diff --git a/web/tag-farcaster-channel/create-farcaster-channel-tag-modal.react.js b/web/tag-farcaster-channel/create-farcaster-channel-tag-modal.react.js --- a/web/tag-farcaster-channel/create-farcaster-channel-tag-modal.react.js +++ b/web/tag-farcaster-channel/create-farcaster-channel-tag-modal.react.js @@ -33,7 +33,7 @@ const neynarClientContext = React.useContext(NeynarClientContext); invariant(neynarClientContext, 'NeynarClientContext is missing'); - const { client } = neynarClientContext; + const { client, fcCache } = neynarClientContext; const [channelOptions, setChannelOptions] = React.useState< $ReadOnlyArray, @@ -89,15 +89,13 @@ } const channelInfo = - await neynarClientContext.client.fetchFarcasterChannelByID( - channelNameText, - ); + await fcCache.getFarcasterChannelForChannelID(channelNameText); if (!channelInfo) { setError('channel_not_found'); return; } createTag(channelInfo.id); - }, [channelNameText, createTag, neynarClientContext.client, selectedOption]); + }, [channelNameText, createTag, fcCache, selectedOption]); const buttonDisabled = isLoading ||