diff --git a/packages/server/modules/core/graph/plugins/logging.ts b/packages/server/modules/core/graph/plugins/logging.ts index fdba4f0d2..de88f4171 100644 --- a/packages/server/modules/core/graph/plugins/logging.ts +++ b/packages/server/modules/core/graph/plugins/logging.ts @@ -107,37 +107,44 @@ export const loggingPluginFactory: (deps: { apollo_query_duration_ms: Date.now() - apolloRequestStart }) - for (const err of ctx.errors) { - const operationName = ctx.request.operationName || null - const query = ctx.request.query - const variables = redactSensitiveVariables(ctx.request.variables) + const operationName = ctx.request.operationName || null + const query = ctx.request.query + const variables = redactSensitiveVariables(ctx.request.variables) - const reqCtx = getRequestContext() - if (reqCtx) { - logger = logger.child({ - dbMetrics: reqCtx.dbMetrics - }) - } + const reqCtx = getRequestContext() + if (reqCtx) { + logger = logger.child({ + dbMetrics: reqCtx.dbMetrics + }) + } - if (err.path) { - logger = logger.child({ - 'query-path': err.path.join(' > '), - graphql_operation_name: operationName, - graphql_query: query, - graphql_variables: variables - }) - } - if (shouldLogAsInfoLevel(err)) { - logger.info( - { err }, - '{graphql_operation_title} failed after {apollo_query_duration_ms} ms' - ) - } else { - logger.error( - err, - '{graphql_operation_title} failed after {apollo_query_duration_ms} ms' - ) - } + const importantError = ctx.errors.find((err) => !shouldLogAsInfoLevel(err)) + const firstError = ctx.errors[0] + const loggableError = importantError || firstError + + logger = logger.child({ + error_count: loggableError ? ctx.errors.length : undefined, + first_error: loggableError + ? { + message: loggableError.message, + path: loggableError.path?.join(' > ') + } + : {}, + graphql_operation_name: operationName, + graphql_query: query, + graphql_variables: variables + }) + + if (!importantError) { + logger.info( + { err: firstError }, + '{graphql_operation_title} failed after {apollo_query_duration_ms} ms' + ) + } else { + logger.error( + { err: importantError }, + '{graphql_operation_title} failed after {apollo_query_duration_ms} ms' + ) } }, willSendResponse: async (ctx) => { diff --git a/packages/server/modules/core/graph/resolvers/commits.ts b/packages/server/modules/core/graph/resolvers/commits.ts index 40da4716c..34ee339f4 100644 --- a/packages/server/modules/core/graph/resolvers/commits.ts +++ b/packages/server/modules/core/graph/resolvers/commits.ts @@ -306,8 +306,20 @@ export = { } }, Branch: { - async commits(parent, args) { + async commits(parent, args, ctx) { const projectDB = await getProjectDbClient({ projectId: parent.streamId }) + + // If limit=0 & no filter, short-cut full execution and use data loader + if (args.limit === 0) { + return { + totalCount: await ctx.loaders + .forRegion({ db: projectDB }) + .branches.getCommitCount.load(parent.id), + items: [], + cursor: null + } + } + const getPaginatedBranchCommits = getPaginatedBranchCommitsFactory({ getSpecificBranchCommits: getSpecificBranchCommitsFactory({ db: projectDB }), getPaginatedBranchCommitsItems: getPaginatedBranchCommitsItemsFactory({ diff --git a/packages/server/modules/core/graph/resolvers/streams.ts b/packages/server/modules/core/graph/resolvers/streams.ts index a54c93bb9..e43ce82c5 100644 --- a/packages/server/modules/core/graph/resolvers/streams.ts +++ b/packages/server/modules/core/graph/resolvers/streams.ts @@ -206,6 +206,8 @@ export = { }, async streams(_, args, ctx) { + const countOnly = args.limit === 0 && !args.query + const [totalCount, visibleCount, { cursor, streams }] = await Promise.all([ getUserStreamsCount({ userId: ctx.userId!, @@ -220,15 +222,17 @@ export = { streamIdWhitelist: toProjectIdWhitelist(ctx.resourceAccessRules), onlyWithActiveSsoSession: true }), - getUserStreams({ - userId: ctx.userId!, - limit: args.limit, - cursor: args.cursor || undefined, - searchQuery: args.query || undefined, - forOtherUser: false, - streamIdWhitelist: toProjectIdWhitelist(ctx.resourceAccessRules), - onlyWithActiveSsoSession: true - }) + !countOnly + ? getUserStreams({ + userId: ctx.userId!, + limit: args.limit, + cursor: args.cursor || undefined, + searchQuery: args.query || undefined, + forOtherUser: false, + streamIdWhitelist: toProjectIdWhitelist(ctx.resourceAccessRules), + onlyWithActiveSsoSession: true + }) + : { cursor: null, streams: [] } ]) return {