import_antigravity
import_antigravity
TTCTheo's Typesafe Cult
Created by import_antigravity on 6/27/2023 in #questions
tanstack query (requests in bulk vs individual)
- There are times where I need to make requests for specific objects from my database, but there can be many objects per page. Currently, I am just doing a useQuery per object that I need. That works fine but I think it may be better at this point to just request the specific objects that I need all at once, as in, make a request for the specific ids that I want in a single request. That way there are fewer requests and fewer calls to my database. The problem then, is that I cannot make use of the nice caching mechanism that tanstack query provides. An idea of what I'm going for is like this:
fn useItem(id: number) {
useQuery(['item', id], api.getItem(id), {...opts}),
}

async fn useManyItems(idList: number[]) {
// check if these items are currently being cached and remove them from the list if they are

// for those that are not cached, get them
const response = await api.getManyItems(idList)

// for the items in this response, map the values to the `singular item` type of query so that future calls to `useManyItems` with that id do not re-request it
}
fn useItem(id: number) {
useQuery(['item', id], api.getItem(id), {...opts}),
}

async fn useManyItems(idList: number[]) {
// check if these items are currently being cached and remove them from the list if they are

// for those that are not cached, get them
const response = await api.getManyItems(idList)

// for the items in this response, map the values to the `singular item` type of query so that future calls to `useManyItems` with that id do not re-request it
}
I skimmed the docs but didn't see anything pop out to me, does anyone know of anything that would provide this sort of function off the top of their head?
10 replies
TTCTheo's Typesafe Cult
Created by import_antigravity on 11/6/2022 in #questions
trpc response time
I have a situation where I need to record the response time of a request. If I wasn't using trpc, I would just record the start time, await the response and record the end time. Is there a way to do this, while using trpc?
5 replies