djbalinD
Convex Communityโ€ข9mo agoโ€ข
1 reply
djbalin

Caching subpart of query

Hello ๐ŸŒ…

Context
In our video streaming app, we have an expensive query that fetches the home feed for our users. This query fetches the same videos for all our users, and so it is obvious to leverage cache for this.
const data = useQuery(api.videos.getStaticFeed, {}) // can be cached for all users


However, we have implemented a personal content filtering system whereby each individual user can enable/disable certain channels or topics. We must therefore pass the userid to this query and check whether they have any filters set up:
const data = useQuery(api.videos.getStaticFeed, {profileId}) // is not cached since profileId is user-unique


Problem
Since we pass a unique argument for every user, our cache is invalidated (and our bandwidth very high). I would like to do this content filtering on the backend and not the frontend. We can not leverage
ctx.auth.userIdentity
since a user can have multiple
profiles
and each profile can have their own filters set up.

Question
We are still fetching the same data for every user in
getStaticFeed
and then just performing some post-filtering based on the
profileId
. Is it possible to somehow cache this sub-query within
getStaticFeed
? If i use
ctx.runQuery
, would that call be cached? Using that approach is discouraged per docs due to extra overhead, however.

Thanks!
Was this page helpful?