diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java index b3d05b3de6..71c17060e4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java @@ -49,6 +49,8 @@ public class Action extends BaseDomain { @JsonProperty(access = JsonProperty.Access.READ_ONLY) Set jsonPathKeys; + String cacheResponse; + public Datasource getDatasource() { if (this.datasource != null) { //The action object has been created from JSON. diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java index f877773c18..1d3eed9eaf 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java @@ -25,7 +25,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; import org.springframework.data.mongodb.core.ReactiveMongoTemplate; import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.stereotype.Service; @@ -368,7 +367,25 @@ public class ActionServiceImpl extends BaseService obj); + .flatMap(obj -> obj) + .flatMap(result -> { + Mono resultMono = Mono.just(result); + Mono actionFromDbMono = repository.findById(actionFromDto.getId()) + //If the action is found in the db (i.e. it is not a dry run, save the cached response + .flatMap(action -> { + if (result.getStatusCode().charAt(0) == '2') { + //If the status code is 2xx, then save the cached response (aka the body) and return. + action.setCacheResponse(result.getBody().toString()); + return repository.save(action); + } + return Mono.just(action); + }); + return actionFromDbMono.zipWith(resultMono) + .map(tuple -> { + ActionExecutionResult executionResult = tuple.getT2(); + return executionResult; + }); + }); } @Override