You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The current implementation in /server/api/trpc.ts applies artificial delays in both development and production, leading to unnecessary performance issues in production. This will improve performance in production environments while still providing the delay in development for simulating network latency.
Describe the solution you'd like to see
Refactor the timingMiddleware to only apply artificial delays during development (t._config.isDev) and not in production.
FROM
const timingMiddleware = t.middleware(async ({ next, path }) => {
const start = Date.now();
if (t._config.isDev) {
// artificial delay in dev
const waitMs = Math.floor(Math.random() * 400) + 100;
await new Promise((resolve) => setTimeout(resolve, waitMs));
}
const result = await next();
const end = Date.now();
console.log(`[TRPC] ${path} took ${end - start}ms to execute`);
return result;
});
export const publicProcedure = t.procedure.use(timingMiddleware);
wolfcarves
changed the title
Refactor trpc.ts for better performance and environment-specific middleware
Refactor trpc.ts Middleware for Better Production Performance
May 13, 2025
Is your feature request related to a problem? Please describe.
The current implementation in
/server/api/trpc.ts
applies artificial delays in both development and production, leading to unnecessary performance issues in production. This will improve performance in production environments while still providing the delay in development for simulating network latency.Describe the solution you'd like to see
Refactor the
timingMiddleware
to only apply artificial delays during development (t._config.isDev) and not in production.FROM
TO
Describe alternate solutions
For a simplier approach
Additional information
No response
The text was updated successfully, but these errors were encountered: