Page MenuHomePhabricator

[lib] cache led channels response from neynar
ClosedPublic

Authored by varun on Oct 2 2024, 10:05 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 18, 9:06 AM
Unknown Object (File)
Wed, Dec 18, 9:06 AM
Unknown Object (File)
Wed, Dec 18, 9:06 AM
Unknown Object (File)
Wed, Dec 18, 9:06 AM
Unknown Object (File)
Sat, Nov 23, 3:47 AM
Unknown Object (File)
Nov 10 2024, 12:28 PM
Unknown Object (File)
Nov 10 2024, 12:17 PM
Unknown Object (File)
Nov 8 2024, 10:38 PM
Subscribers

Details

Summary

we call this client method a lot from keyserver when a farcaster user auto joins communities. we should cache the response from neynar for a minute to avoid making unnecessary calls.

part of: https://linear.app/comm/issue/ENG-9473/app-freezes-when-user-with-a-popular-farcaster-user-joins

Test Plan

checked how many times the neynar API was called and it went down from hundreds to just 5

Diff Detail

Repository
rCOMM Comm
Branch
master
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

maybe an LRU cache would've made more sense than a TTL

varun requested review of this revision.Oct 2 2024, 10:22 PM

We can go with this approach for now, but I think it would be better to replace the API so we're only querying one channel at a time. It's true that we'd end up with N Neynar queries instead of 1 Neynar query for N channels that get cached, but I think it's better to avoid the massive query at the start, and hopefully it's not expensive to do single "point queries" to Neynar

lib/utils/neynar-client.js
172

I don't think it makes sense to keep this API here. We should replace it with one that takes an FID and a channel, and we could cache the results of that one

176

Do we really need to re-check the TTL here after we just called this.cleanExpiredCacheEntries? I get that the current timestamp might've changed, but not sure it really matters

This revision is now accepted and ready to land.Oct 3 2024, 12:01 AM
lib/utils/neynar-client.js
172
176

fair. i'll just check if (cachedEntry)