-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of ApolloFederatedTracing
wrapper
#2167
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,41 +98,50 @@ object ApolloFederatedTracing { | |
wrapPureValues: Boolean | ||
): FieldWrapper[Any] = | ||
new FieldWrapper[Any](wrapPureValues) { | ||
|
||
private def updateState(startTime: Long, fieldInfo: FieldInfo)(result: Either[ExecutionError, ResponseValue]) = | ||
ZQuery.succeed { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we even need to wrap this? We only execute it within a foldQuery. Could we just execute purely and then lift the result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think that's better actually. I'll do the change |
||
val endTime = nanoTime | ||
val path = (PathValue.Key(fieldInfo.name) :: fieldInfo.path).toVector | ||
val _ = ref.updateAndGet(state => | ||
state.copy( | ||
root = state.root.insert( | ||
path, | ||
Node( | ||
id = Node.Id.ResponseName(fieldInfo.name), | ||
startTime = startTime - state.startTime, | ||
endTime = endTime - state.startTime, | ||
`type` = fieldInfo.details.fieldType.toType().toString, | ||
parentType = fieldInfo.details.parentType.map(_.toType().toString) getOrElse "", | ||
originalFieldName = fieldInfo.details.alias.map(_ => fieldInfo.details.name) getOrElse "", | ||
error = result.left.toOption.collectFirst { case e: ExecutionError => | ||
Error( | ||
e.getMessage(), | ||
location = e.locationInfo.map(l => Location(l.line, l.column)).toSeq | ||
) | ||
}.toSeq | ||
) | ||
) | ||
) | ||
) | ||
result match { | ||
case Right(value) => value | ||
case _ => null | ||
} | ||
} | ||
|
||
def wrap[R1]( | ||
query: ZQuery[R1, CalibanError.ExecutionError, ResponseValue], | ||
fieldInfo: FieldInfo | ||
): ZQuery[R1, CalibanError.ExecutionError, ResponseValue] = | ||
if (enabled.get()) | ||
ZQuery.suspend { | ||
val startTime = nanoTime | ||
query.either.flatMap { result => | ||
ZQuery.fromEither { | ||
val endTime = nanoTime | ||
val path = (PathValue.Key(fieldInfo.name) :: fieldInfo.path).toVector | ||
val _ = ref.updateAndGet(state => | ||
state.copy( | ||
root = state.root.insert( | ||
path, | ||
Node( | ||
id = Node.Id.ResponseName(fieldInfo.name), | ||
startTime = startTime - state.startTime, | ||
endTime = endTime - state.startTime, | ||
`type` = fieldInfo.details.fieldType.toType().toString, | ||
parentType = fieldInfo.details.parentType.map(_.toType().toString) getOrElse "", | ||
originalFieldName = fieldInfo.details.alias.map(_ => fieldInfo.details.name) getOrElse "", | ||
error = result.left.toOption.collectFirst { case e: ExecutionError => | ||
Error( | ||
e.getMessage(), | ||
location = e.locationInfo.map(l => Location(l.line, l.column)).toSeq | ||
) | ||
}.toSeq | ||
) | ||
) | ||
) | ||
) | ||
result | ||
} | ||
} | ||
val update0 = updateState(startTime, fieldInfo) _ | ||
query.foldQuery( | ||
error => update0(Left(error)) *> ZQuery.fail(error), | ||
value => update0(Right(value)) | ||
) | ||
} | ||
else query | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this wasn't an implicit 🤦♂️