feat(server): greatly optimizing Branch.commits & Query.streams, when limit=0 (#3863)
* fix(server): optimize Branch.commits resolver * feat(server): optimizing Query.streams a bit too * fix(server): gql error req duplicate entries logged
This commit is contained in:
committed by
GitHub
parent
71b82f2cb2
commit
b074a4a13a
@@ -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) => {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user