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)
Sun, Nov 10, 12:28 PM
Unknown Object (File)
Sun, Nov 10, 12:17 PM
Unknown Object (File)
Fri, Nov 8, 10:38 PM
Unknown Object (File)
Fri, Nov 8, 1:48 PM
Unknown Object (File)
Sat, Nov 2, 6:06 PM
Unknown Object (File)
Fri, Nov 1, 4:00 PM
Unknown Object (File)
Fri, Nov 1, 3:19 AM
Unknown Object (File)
Thu, Oct 31, 1:11 AM
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
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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 ↗(On Diff #44848)

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 ↗(On Diff #44848)

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 ↗(On Diff #44848)
176 ↗(On Diff #44848)

fair. i'll just check if (cachedEntry)