Skip to content

fix: enforce the HasLimit req by Explain #257

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -69,7 +69,7 @@ data class ExplainQuery(
val explainPlanQueryResult = runCatching {
// Ensuring that the query at-least has a limit if it doesn't already because
// the explain is run automatically
from.runQuery(query.with(HasLimit(1)), Map::class, queryContext)
from.runQuery(query.withReplaced(HasLimit(1)), Map::class, queryContext)
}.getOrNull() ?: return ExplainQuery(ExplainPlan.NotRun)

val explainPlanDoc =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ data class Node<S>(
return copy(components = components + component)
}

fun withReplaced(component: Component): Node<S> {
val componentClass = component::class
val newComponents = components.map {
if (it::class == componentClass) component else it
}

val replaced = newComponents.any { it === component }
return if (replaced) {
copy(components = newComponents)
} else {
copy(components = components + component)
}
}

fun componentsWithChildren(): List<HasChildren<S>> = components.filterIsInstance<HasChildren<S>>()

inline fun <reified C : Component> hasComponent(): Boolean = component<C>() != null
Expand Down
Loading