From e5a9d16d7e39fb2dc38f5d673e4da856bdd71cc9 Mon Sep 17 00:00:00 2001 From: Steven H Date: Thu, 14 Mar 2024 11:41:11 +0000 Subject: [PATCH] Mitigate long loading times on spaces with many files. (#260) --- sentry.client.config.ts | 7 +++++-- sentry.server.config.ts | 12 ++++++++++-- src/lib/api.ts | 3 +++ src/lib/cache/cache.ts | 10 +++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/sentry.client.config.ts b/sentry.client.config.ts index 401a5a935..e8748c7ed 100644 --- a/sentry.client.config.ts +++ b/sentry.client.config.ts @@ -3,9 +3,12 @@ import * as Sentry from '@sentry/nextjs'; const dsn = process.env.SENTRY_DSN; if (dsn) { Sentry.init({ - dsn, - tracesSampleRate: 0.01, debug: false, + dsn, integrations: [], + enableTracing: false, + beforeSendTransaction: () => { + return null; + }, }); } diff --git a/sentry.server.config.ts b/sentry.server.config.ts index e7c031f3d..10df05a84 100644 --- a/sentry.server.config.ts +++ b/sentry.server.config.ts @@ -3,8 +3,16 @@ import * as Sentry from '@sentry/nextjs'; const dsn = process.env.SENTRY_DSN; if (dsn) { Sentry.init({ - dsn, - tracesSampleRate: 0.01, debug: false, + dsn, + + // Disable tracing as it creates additional requests in an env where subrequests are limited. + enableTracing: false, + + // Disable transactions as it creates additional requests in an env where subrequests are limited. + // https://docs.sentry.io/platforms/node/configuration/filtering/#using--3 + beforeSendTransaction: () => { + return null; + }, }); } diff --git a/src/lib/api.ts b/src/lib/api.ts index 27491e797..68091331b 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -482,6 +482,9 @@ const getRevisionAllFiles = cache( return cacheResponse(response, { ...immutableCacheTtl_7days, data: files }); }, + { + timeout: 60 * 1000, + } ); /** diff --git a/src/lib/cache/cache.ts b/src/lib/cache/cache.ts index 7f020314f..4329c71bc 100644 --- a/src/lib/cache/cache.ts +++ b/src/lib/cache/cache.ts @@ -63,8 +63,14 @@ export function cache( /** Default ttl (in seconds) */ defaultTtl?: number; + + /** When a request to the underlying resource will timeout. */ + timeout?: number; } = {}, ): CacheFunction { + // We stop everything after 10s to avoid pending requests + const timeout = options.timeout ?? 1000 * 10; + const revalidate = singletonMap( async (key: string, signal: AbortSignal | undefined, ...args: Args) => { return await trace( @@ -131,9 +137,7 @@ export function cache( }, { signal, - - // We stop everything after 10s to avoid pending requests - timeout: 10 * 1000, + timeout, // We give 70ms to the caches to respond, otherwise we start fallbacking to the actual fetch // It should represents a bit more than the 90th percentile of the KV cache response time