feat(objects): Improve gql loading logic around limits (#4885)
This commit is contained in:
committed by
GitHub
parent
e4657adf48
commit
2cd108c3ee
@@ -50,25 +50,9 @@ import { StreamNotFoundError } from '@/modules/core/errors/stream'
|
||||
import { throwIfResourceAccessNotAllowed } from '@/modules/core/helpers/token'
|
||||
import { TokenResourceIdentifierType } from '@/modules/core/domain/tokens/types'
|
||||
import { throwIfAuthNotOk } from '@/modules/shared/helpers/errorHelper'
|
||||
import { Version } from '@/modules/core/domain/commits/types'
|
||||
import { GraphQLResolveInfo } from 'graphql'
|
||||
import { withOperationLogging } from '@/observability/domain/businessLogging'
|
||||
import { isCreatedBeyondHistoryLimitCutoffFactory } from '@/modules/gatekeeperCore/utils/limits'
|
||||
|
||||
/**
|
||||
* Simple utility to check if version is inside a Model or a Project
|
||||
*/
|
||||
const getTypeFromPath = (info: GraphQLResolveInfo): 'Model' | 'Project' | null => {
|
||||
let currentPath = info.path
|
||||
while (currentPath) {
|
||||
if (currentPath.typename === 'Model' || currentPath.typename === 'Project') {
|
||||
return currentPath.typename
|
||||
}
|
||||
currentPath = currentPath.prev!
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const throwIfRateLimited = throwIfRateLimitedFactory({
|
||||
rateLimiterEnabled: isRateLimiterEnabled()
|
||||
})
|
||||
@@ -116,7 +100,7 @@ export = {
|
||||
const path = `/preview/${stream.id}/commits/${parent.id}`
|
||||
return new URL(path, getServerOrigin()).toString()
|
||||
},
|
||||
referencedObject: async (parent, _args, ctx, info) => {
|
||||
referencedObject: async (parent, _args, ctx) => {
|
||||
const projectDB = await getProjectDbClient({ projectId: parent.streamId })
|
||||
const project = await ctx.loaders
|
||||
.forRegion({ db: projectDB })
|
||||
@@ -134,22 +118,11 @@ export = {
|
||||
project
|
||||
})
|
||||
|
||||
let latestVersion: Version | null = null
|
||||
let latestVersions: Array<Version> | null = null
|
||||
if (getTypeFromPath(info) === 'Model') {
|
||||
latestVersion = await ctx.loaders
|
||||
.forRegion({ db: projectDB })
|
||||
.branches.getLatestCommit.load(parent.branchId)
|
||||
} else {
|
||||
latestVersions = await ctx.loaders
|
||||
.forRegion({ db: projectDB })
|
||||
.streams.getLatestVersions.load(parent.streamId)
|
||||
}
|
||||
const latestVersions = await ctx.loaders
|
||||
.forRegion({ db: projectDB })
|
||||
.streams.getLatestVersions.load(parent.streamId)
|
||||
|
||||
if (
|
||||
latestVersion?.id === parent.id ||
|
||||
latestVersions?.find((lv) => lv.id === parent.id)
|
||||
)
|
||||
if (latestVersions?.find((lv) => lv.id === parent.id))
|
||||
return parent.referencedObject
|
||||
if (isBeyondLimit) return null
|
||||
return parent.referencedObject
|
||||
|
||||
Reference in New Issue
Block a user