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

Reduce response payload size for scenarios tab #7354

Open
wants to merge 3 commits into
base: staging
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 @@ -182,7 +182,7 @@ class AppApiHttpService(
processService
.getLatestProcessesWithDetails(
ScenarioQuery.unarchivedProcesses,
GetScenarioWithDetailsOptions.withsScenarioGraph.withValidation
GetScenarioWithDetailsOptions.withScenarioGraph.withValidation
)
.map { processes =>
processes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import pl.touk.nussknacker.ui.process.ProcessService.{
CreateScenarioCommand,
FetchScenarioGraph,
GetScenarioWithDetailsOptions,
SkipAdditionalFields,
UpdateScenarioCommand
}
import pl.touk.nussknacker.ui.process.ScenarioWithDetailsConversions._
Expand Down Expand Up @@ -81,7 +82,7 @@ class ProcessesResources(
complete {
processService.getLatestProcessesWithDetails(
query,
GetScenarioWithDetailsOptions.detailsOnly.withFetchState
GetScenarioWithDetailsOptions.withoutAdditionalFields.withFetchState
)
}
}
Expand Down Expand Up @@ -232,12 +233,12 @@ class ProcessesResources(
thisVersion <- processService.getProcessWithDetails(
processId,
thisVersion,
GetScenarioWithDetailsOptions.withsScenarioGraph
GetScenarioWithDetailsOptions.withScenarioGraph
)
otherVersion <- processService.getProcessWithDetails(
processId,
otherVersion,
GetScenarioWithDetailsOptions.withsScenarioGraph
GetScenarioWithDetailsOptions.withScenarioGraph
)
} yield ScenarioGraphComparator.compare(thisVersion.scenarioGraphUnsafe, otherVersion.scenarioGraphUnsafe)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RemoteEnvironmentResources(
for {
processes <- processService.getLatestProcessesWithDetails(
ScenarioQuery.unarchived,
GetScenarioWithDetailsOptions.withsScenarioGraph
GetScenarioWithDetailsOptions.withScenarioGraph
)
comparison <- compareProcesses(processes)
} yield NuDesignerErrorToHttp.toResponseEither(comparison)
Expand Down Expand Up @@ -137,7 +137,7 @@ class RemoteEnvironmentResources(
.getProcessWithDetails(
processIdWithName,
version,
GetScenarioWithDetailsOptions.withsScenarioGraph
GetScenarioWithDetailsOptions.withScenarioGraph
)
.flatMap(fun)
.map(NuDesignerErrorToHttp.toResponseEither[T])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,19 @@ object ProcessService {
val detailsOnly: GetScenarioWithDetailsOptions =
new GetScenarioWithDetailsOptions(SkipScenarioGraph, fetchState = false)

val withsScenarioGraph: GetScenarioWithDetailsOptions =
val withScenarioGraph: GetScenarioWithDetailsOptions =
new GetScenarioWithDetailsOptions(FetchScenarioGraph(), fetchState = false)

val withoutAdditionalFields: GetScenarioWithDetailsOptions =
detailsOnly.copy(additionalFieldsOptions = SkipAdditionalFields(skipProcessActionOptionalFields = true))

}

final case class GetScenarioWithDetailsOptions(fetchGraphOptions: ScenarioGraphOptions, fetchState: Boolean) {
final case class GetScenarioWithDetailsOptions(
fetchGraphOptions: ScenarioGraphOptions,
fetchState: Boolean,
additionalFieldsOptions: AdditionalFieldsOptions = DoNotSkipAdditionalFields
) {

def withValidation: GetScenarioWithDetailsOptions = {
val newFetchGraphOptions = fetchGraphOptions match {
Expand Down Expand Up @@ -105,6 +113,12 @@ object ProcessService {
case class ValidateAndResolve(includeValidationNodeResults: Boolean = true) extends ValidationMode
}

sealed trait AdditionalFieldsOptions

case object DoNotSkipAdditionalFields extends AdditionalFieldsOptions

case class SkipAdditionalFields(skipProcessActionOptionalFields: Boolean) extends AdditionalFieldsOptions

}

trait ProcessService {
Expand Down Expand Up @@ -257,6 +271,12 @@ class DBProcessService(
case FetchScenarioGraph(validate) =>
fetchScenario[CanonicalProcess]
.map(_.map(validateAndReverseResolve(_, validate)))
}).map(_.map { details =>
options.additionalFieldsOptions match {
case DoNotSkipAdditionalFields => details
case skipFieldsOption: SkipAdditionalFields =>
ScenarioWithDetailsConversions.skipAdditionalFields(details, skipFieldsOption)
}
}).flatMap { details =>
if (options.fetchState)
processStateProvider.enrichDetailsWithProcessState(details)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package pl.touk.nussknacker.ui.process

import pl.touk.nussknacker.engine.api.deployment.ProcessAction
import pl.touk.nussknacker.engine.api.graph.ScenarioGraph
import pl.touk.nussknacker.engine.api.process.ProcessId
import pl.touk.nussknacker.restmodel.scenariodetails.{ScenarioParameters, ScenarioWithDetails}
import pl.touk.nussknacker.restmodel.validation.ScenarioGraphWithValidationResult
import pl.touk.nussknacker.ui.process.ProcessService.SkipAdditionalFields
import pl.touk.nussknacker.ui.process.repository.ScenarioWithDetailsEntity

object ScenarioWithDetailsConversions {
Expand Down Expand Up @@ -55,6 +57,25 @@ object ScenarioWithDetailsConversions {
)
}

def skipAdditionalFields(details: ScenarioWithDetails, skipOptions: SkipAdditionalFields): ScenarioWithDetails = {
def skipProcessActionOptionalFields(processAction: Option[ProcessAction]) = processAction.map(
_.copy(
failureMessage = None,
commentId = None,
comment = None,
buildInfo = Map.empty
)
)
def getProcessAction(processAction: Option[ProcessAction]) =
if (skipOptions.skipProcessActionOptionalFields) skipProcessActionOptionalFields(processAction) else processAction

details.copy(
lastDeployedAction = getProcessAction(details.lastDeployedAction),
lastStateAction = getProcessAction(details.lastStateAction),
lastAction = getProcessAction(details.lastAction)
)
}

implicit class Ops(scenarioWithDetails: ScenarioWithDetails) {

// TODO: Instead of doing these conversions below, wee should pass around ScenarioWithDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object UsageStatisticsReportsSettingsService extends LazyLogging {
processService
.getLatestProcessesWithDetails(
ScenarioQuery.unarchived,
GetScenarioWithDetailsOptions.withsScenarioGraph.withFetchState
GetScenarioWithDetailsOptions.withScenarioGraph.withFetchState
)(user)
.map { scenariosDetails =>
Right(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ class ProcessesResourcesSpec
}
}

test("/api/processes should return lighter details without ProcessAction's additional fields") {
createDeployedWithCustomActionScenario(processName, category = Category1)
Get(s"/api/processes") ~> withReaderUser() ~> applicationRoute ~> check {
status shouldEqual StatusCodes.OK
val loadedProcess = responseAs[List[ScenarioWithDetails]]

loadedProcess.head.lastAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, _, _, None, None, None, buildInfo)
) if buildInfo.isEmpty =>
}
loadedProcess.head.lastStateAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, _, _, None, None, None, buildInfo)
) if buildInfo.isEmpty =>
}
loadedProcess.head.lastDeployedAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, _, _, None, None, None, buildInfo)
) if buildInfo.isEmpty =>
}
}
}

test("return single process") {
createDeployedExampleScenario(processName, category = Category1)
MockableDeploymentManager.configureScenarioStatuses(
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* [#7341](https://github.com/TouK/nussknacker/pull/7341) Added possibility to choose presets and define lists for Integer typed parameter inputs in fragments.
* [#7356](https://github.com/TouK/nussknacker/pull/7356) Integers converted to BigDecimals have scale 18,
this fixes issue with unexpected low scale when performing division on BigDecimals which were created in such conversion.
* [#7354](https://github.com/TouK/nussknacker/pull/7354) Reduce response payload size when fetching scenarios for scenarios tab by removing unused fields.

## 1.18

Expand Down
Loading