Skip to content

Conversation

@alexcambose
Copy link
Contributor

@alexcambose alexcambose commented Aug 4, 2025

Summary

The issue is around having a lot of our UI data coming from a call to get pyth metadata.
Now we use a redis cache for storing function call results (functions that would require the pyth metadata or clickhouse data), and also API endpoints for native nextjs caching.

The pyth metadata function call is stored in an in memory cache and deduped if there are multiple calls at the same time.

Cache TTL is 24h with a stale of another 24h.

Rationale

Caching data that we don't need to be up to date to make everything faster.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

@vercel
Copy link

vercel bot commented Aug 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
component-library Ready Ready Preview Comment Aug 18, 2025 8:33am
insights Ready Ready Preview Comment Aug 18, 2025 8:33am
6 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
api-reference Skipped Skipped Aug 18, 2025 8:33am
developer-hub Skipped Skipped Aug 18, 2025 8:33am
entropy-debugger Skipped Skipped Aug 18, 2025 8:33am
entropy-explorer Skipped Skipped Aug 18, 2025 8:33am
proposals Skipped Skipped Aug 18, 2025 8:33am
staking Skipped Skipped Aug 18, 2025 8:33am

@vercel vercel bot temporarily deployed to Preview – entropy-explorer August 4, 2025 10:09 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals August 4, 2025 10:09 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference August 4, 2025 10:09 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger August 4, 2025 10:09 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub August 4, 2025 10:09 Inactive
@vercel vercel bot temporarily deployed to Preview – staking August 4, 2025 10:09 Inactive
@vercel vercel bot temporarily deployed to Preview – staking August 4, 2025 13:28 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference August 4, 2025 13:28 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer August 4, 2025 13:28 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger August 4, 2025 13:28 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals August 4, 2025 13:28 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub August 4, 2025 13:28 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference August 4, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals August 4, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – staking August 4, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer August 4, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub August 4, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger August 4, 2025 13:40 Inactive
@alexcambose alexcambose changed the title feat: add cached methods feat(insights): add cached methods Aug 4, 2025
Copy link
Collaborator

@cprussin cprussin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looking really good. My main feedback is to get rid of typecasting wherever possible. Other than that I recommend adding some comments to explain why using internal fetches is necessary here and the steps you've tried to avoid doing that since it's not really intuitive why we landed on this architecture as a necessity, and it would be easy for someone to not understand it and try to refactor it away without realizing the issues

return NextResponse.json({ error: "Invalid cluster" }, { status: 400 });
}

let feeds = await getFeedsCached(cluster) as Omit<z.infer<typeof priceFeedsSchema>[number], 'price'>[];
Copy link
Collaborator

@cprussin cprussin Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not typecast here, the typecast will be unnecessary if you just do this like this:

const feeds = await getFeedsCached(cluster);
return NextResponse.json(stringify(
  excludePriceComponents ? feeds.map(({ price, ...feed }) => feed) : feeds
));

} else {
return `http://localhost:3003`;
}
})();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcambose I think this comment still stands, I would get rid of this config and just use the request origin when building urls

@alexcambose
Copy link
Contributor Author

@cprussi added a helper function to use the headers, lmk if it makes sense! I'll go ahead and merge this

@alexcambose alexcambose merged commit c166d1c into main Aug 18, 2025
10 checks passed
@alexcambose alexcambose deleted the feat/perf-caching branch August 18, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants