Skip to content
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

[IJ Plugin] Fix high latency field inspection #6142

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ data class ApolloKotlinService(

@XCollection
val endpointHeaders: Map<String, String>? = null,

@XCollection
val upstreamServiceIds: List<Id> = emptyList(),
) {
data class Id(
@Attribute
Expand All @@ -52,21 +55,19 @@ data class ApolloKotlinService(
val serviceName: String = "",
) {
override fun toString(): String {
val formattedPath = gradleProjectPath.split(":").filterNot { it.isEmpty() }.joinToString("-")
return "$formattedPath/$serviceName"
return "$gradleProjectPath/$serviceName"
}

companion object {
fun fromString(string: String): Id? {
val split = string.split("/")
val split = string.split("/", limit = 2)
if (split.size != 2) return null
return Id(split[0], split[1])
}
}
}

val id
val id: Id
@Transient
get() = Id(gradleProjectPath, serviceName)

}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class GradleToolingModelService(
.distinct(),
endpointUrl = serviceInfo.endpointUrlCompat(toolingModel),
endpointHeaders = serviceInfo.endpointHeadersCompat(toolingModel),
upstreamServiceIds = upstreamApolloKotlinServices.map { it.id }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,20 @@ class FieldInsightsServiceImpl(private val project: Project) : FieldInsightsServ
return fieldLatenciesByService.isNotEmpty()
}

private fun getFieldLatenciesForService(serviceId: ApolloKotlinService.Id): FieldInsights.FieldLatencies? {
if (fieldLatenciesByService.containsKey(serviceId)) {
return fieldLatenciesByService[serviceId]
}
// Try upstream services
val apolloKotlinService = GradleToolingModelService.getApolloKotlinServices(project).firstOrNull { it.id == serviceId } ?: return null
for (upstreamServiceId in apolloKotlinService.upstreamServiceIds) {
return getFieldLatenciesForService(upstreamServiceId) ?: continue
}
return null
}

override fun getLatency(serviceId: ApolloKotlinService.Id, typeName: String, fieldName: String): Double? {
return fieldLatenciesByService[serviceId]?.getLatency(parentType = typeName, fieldName = fieldName)
return getFieldLatenciesForService(serviceId)?.getLatency(parentType = typeName, fieldName = fieldName)
}

private fun refreshInspections() {
Expand Down
Loading