rustclan
rustclan
TtRPC
Created by rustclan on 2/17/2024 in #❓-help
What is a useSuspenseQuery?
okay thank you
3 replies
TtRPC
Created by rustclan on 9/22/2023 in #❓-help
return type of a query endpoint
Sorry, I just saw these messages. At the moment I mainly use refetch to update the response once something has been updated/deleted. I should probably just return the updated document in the response to the mutation, or in the case of a delete just remove it from the original data list. Would be more efficient for sure.
8 replies
TtRPC
Created by rustclan on 9/22/2023 in #❓-help
return type of a query endpoint
Thank you!
8 replies
TtRPC
Created by rustclan on 4/30/2023 in #❓-help
TRPC ratelimiting endpoints
Hmm, yes okay. I see what you are saying. This depends on vercel runs nextjs api endpoints, im not entirely sure. For now, this is working just fine. But I should look into this just encase. Thank you very much for the help 🙂
20 replies
TtRPC
Created by rustclan on 4/30/2023 in #❓-help
TRPC ratelimiting endpoints
But just so I understand, why does this solution not scale? You say I may have to deal with the promise in redis? Why is using memo not okay?
20 replies
TtRPC
Created by rustclan on 4/30/2023 in #❓-help
TRPC ratelimiting endpoints
@alex / KATT hi, I had time to do this now. Thank you SO much! This issue was slowing my site down alot, and now it is fast once again!
20 replies
TtRPC
Created by rustclan on 4/30/2023 in #❓-help
TRPC ratelimiting endpoints
Thank you very much, when I get some time I shall look at this.
20 replies
TtRPC
Created by rustclan on 4/30/2023 in #❓-help
TRPC ratelimiting endpoints
Hi, thank you for the response. But I'm not sure I follow. Since this is hosted on serverless infrastructure (vercel), I don't think this is possible to use a in memory cache to stop this from happening? I may be misunderstanding your solution though.
20 replies
TtRPC
Created by rustclan on 4/30/2023 in #❓-help
TRPC ratelimiting endpoints
bump
20 replies
TtRPC
Created by rustclan on 4/30/2023 in #❓-help
TRPC ratelimiting endpoints
function which needs to be ratelimited (using the redis cache)
export const getUserGuilds = async (
session: Session
): Promise<CachedUserGuild[] | null> => {
if (!session.user.accessToken || !session.user.id) return null;

const webUser = await cache.webUsers.get(session.user.id);
if (webUser) return webUser.guilds;

const response = await fetch(discord...)
const guilds = await response.json();
if (!response.ok || guilds.length <= 0) return null;

// add guilds to cache
await cache.webUsers.create(session.user.id, guilds);

return guilds;
};
export const getUserGuilds = async (
session: Session
): Promise<CachedUserGuild[] | null> => {
if (!session.user.accessToken || !session.user.id) return null;

const webUser = await cache.webUsers.get(session.user.id);
if (webUser) return webUser.guilds;

const response = await fetch(discord...)
const guilds = await response.json();
if (!response.ok || guilds.length <= 0) return null;

// add guilds to cache
await cache.webUsers.create(session.user.id, guilds);

return guilds;
};
A big band aid fix would be to just add an artificial wait:
if (!guilds) {
await new Promise((resolve) => setTimeout(resolve, 1000));
webUser = await cache.webUsers.get(ctx.session.user.id);
guilds = webUser?.guilds;
if (!guilds) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
}
if (!guilds) {
await new Promise((resolve) => setTimeout(resolve, 1000));
webUser = await cache.webUsers.get(ctx.session.user.id);
guilds = webUser?.guilds;
if (!guilds) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
}
But obviously this is not very elegant..
20 replies
TtRPC
Created by rustclan on 4/17/2023 in #❓-help
trpc auto refreshes page when I lose focus
Hi. Thank you 🙂 I have found refetchOnWindowFocus which is what I am looking for. Here is my fix for any future people.
export const api = createTRPCNext<AppRouter>({
config() {
return {
transformer: superjson,
queryClientConfig: {
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
},
},
export const api = createTRPCNext<AppRouter>({
config() {
return {
transformer: superjson,
queryClientConfig: {
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
},
},
https://tanstack.com/query/v4/docs/react/guides/window-focus-refetching
5 replies
TtRPC
Created by rustclan on 4/15/2023 in #❓-help
trpc rate limiting
A big band aid fix would be to just add an artificial wait:
if (!guilds) {
await new Promise((resolve) => setTimeout(resolve, 1000));
webUser = await cache.webUsers.get(ctx.session.user.id);
guilds = webUser?.guilds;
if (!guilds) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
}
if (!guilds) {
await new Promise((resolve) => setTimeout(resolve, 1000));
webUser = await cache.webUsers.get(ctx.session.user.id);
guilds = webUser?.guilds;
if (!guilds) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
}
But obviously this is not very elegant..
3 replies
TtRPC
Created by rustclan on 4/15/2023 in #❓-help
trpc rate limiting
hopefully this makes sense, but I am completely stumped about what I can do to resolve this.
3 replies
TtRPC
Created by rustclan on 4/15/2023 in #❓-help
trpc pipe middleware
Thank you! I found a way to do this which was using rawInput prop, but shall give this a read too.
4 replies
TtRPC
Created by rustclan on 2/3/2023 in #❓-help
Calling a trpc endpoint inside of a trpc endpoint
Thanks for the responses guys. 🙂
7 replies
TtRPC
Created by rustclan on 2/3/2023 in #❓-help
Calling a trpc endpoint inside of a trpc endpoint
Oh.. okay. If not this, how else?
7 replies
TtRPC
Created by rustclan on 1/31/2023 in #❓-help
trpc query running twice
Awesome! I'm having a look into redis as we speak. Never used it before though, we'll see what happens!
10 replies
TtRPC
Created by rustclan on 1/31/2023 in #❓-help
trpc query running twice
I like your z_user_schema.parse(data.data); function. Very useful.
10 replies
TtRPC
Created by rustclan on 1/31/2023 in #❓-help
trpc query running twice
Damn... okay. Thank you very much for the information. Much appreciated 🙂
10 replies
TtRPC
Created by rustclan on 1/31/2023 in #❓-help
trpc query running twice
Technically, i could make it so the queries only run once in dev. But, this feature is enabled by default for a reason. Also, doing that is just a band aid fix. What if the user refreshes the page twice? Then my app breaks for a few second and the user gets greeted with a error page. Even though they have already recieved the data from the first request.
10 replies