From 439af21522b29c661a831e8c5fff5ed24e2b7a99 Mon Sep 17 00:00:00 2001 From: tkAppsmith <131347120+tkAppsmith@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:22:52 +0530 Subject: [PATCH] fix: fixed failing queries using aggregation pipeline (#26132) ## Description > Queries using aggregation update failing. hence added a fallback. #### PR fixes following issue(s) Fixes #26090 Fixes https://github.com/appsmithorg/appsmith-ee/issues/1659 #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing > #### How Has This Been Tested? - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- .../newactions/base/NewActionServiceCE.java | 4 +- .../base/NewActionServiceCEImpl.java | 9 ++- .../repositories/BaseRepositoryImpl.java | 4 +- .../CustomNewActionRepositoryImpl.java | 6 +- .../CustomNewPageRepositoryImpl.java | 6 +- .../ce/BaseAppsmithRepositoryCEImpl.java | 6 +- .../ce/CustomNewActionRepositoryCE.java | 2 +- .../ce/CustomNewActionRepositoryCEImpl.java | 42 +++++++--- .../ce/CustomNewPageRepositoryCE.java | 6 +- .../ce/CustomNewPageRepositoryCEImpl.java | 77 ++++++++++++++++--- .../ce/NewActionRepositoryCE.java | 5 ++ .../ce/ApplicationPageServiceCEImpl.java | 5 +- .../server/services/ce/NewPageServiceCE.java | 4 +- .../services/ce/NewPageServiceCEImpl.java | 4 +- .../services/ce/NewActionServiceUnitTest.java | 11 ++- 15 files changed, 144 insertions(+), 47 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java index 8c0e3382c0..20290e0c00 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java @@ -15,7 +15,7 @@ import com.appsmith.server.dtos.ce.ImportActionResultDTO; import com.appsmith.server.dtos.ce.ImportedActionAndCollectionMapsDTO; import com.appsmith.server.helpers.ce.ImportApplicationPermissionProvider; import com.appsmith.server.services.CrudService; -import com.mongodb.client.result.UpdateResult; +import com.mongodb.bulk.BulkWriteResult; import org.springframework.data.domain.Sort; import org.springframework.util.MultiValueMap; import reactor.core.publisher.Flux; @@ -138,7 +138,7 @@ public interface NewActionServiceCE extends CrudService { ImportActionCollectionResultDTO importActionCollectionResultDTO, ImportActionResultDTO importActionResultDTO); - Mono publishActions(String applicationId, AclPermission permission); + Mono> publishActions(String applicationId, AclPermission permission); Flux countActionsByPluginType(String applicationId); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java index 684ac2557d..21d39a3da8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java @@ -54,7 +54,7 @@ import com.appsmith.server.solutions.ApplicationPermission; import com.appsmith.server.solutions.DatasourcePermission; import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PolicySolution; -import com.mongodb.client.result.UpdateResult; +import com.mongodb.bulk.BulkWriteResult; import io.micrometer.observation.ObservationRegistry; import jakarta.validation.Validator; import lombok.extern.slf4j.Slf4j; @@ -664,7 +664,7 @@ public class NewActionServiceCEImpl extends BaseService findAllById(Iterable id) { - return repository.findAllById(id).flatMap(this::sanitizeAction); + return repository.findAllByIdIn(id).flatMap(this::sanitizeAction); } @Override @@ -1908,7 +1908,7 @@ public class NewActionServiceCEImpl extends BaseService { // Update collectionId and defaultCollectionIds in actionDTOs ActionDTO unpublishedAction = newAction.getUnpublishedAction(); @@ -1960,12 +1960,13 @@ public class NewActionServiceCEImpl extends BaseService publishActions(String applicationId, AclPermission permission) { + public Mono> publishActions(String applicationId, AclPermission permission) { // delete the actions that were deleted in edit mode return repository .archiveDeletedUnpublishedActions(applicationId, permission) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/BaseRepositoryImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/BaseRepositoryImpl.java index e21b2265c1..4f4cefc1d6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/BaseRepositoryImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/BaseRepositoryImpl.java @@ -173,7 +173,9 @@ public class BaseRepositoryImpl .flatMapMany(principal -> { Query query = new Query(notDeleted()); return mongoOperations.find( - query, entityInformation.getJavaType(), entityInformation.getCollectionName()); + query.cursorBatchSize(10000), + entityInformation.getJavaType(), + entityInformation.getCollectionName()); }); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewActionRepositoryImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewActionRepositoryImpl.java index e45c7fd224..b3eb05cb8d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewActionRepositoryImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewActionRepositoryImpl.java @@ -2,6 +2,7 @@ package com.appsmith.server.repositories; import com.appsmith.server.repositories.ce.CustomNewActionRepositoryCEImpl; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.ReactiveMongoOperations; import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.stereotype.Component; @@ -14,7 +15,8 @@ public class CustomNewActionRepositoryImpl extends CustomNewActionRepositoryCEIm public CustomNewActionRepositoryImpl( ReactiveMongoOperations mongoOperations, MongoConverter mongoConverter, - CacheableRepositoryHelper cacheableRepositoryHelper) { - super(mongoOperations, mongoConverter, cacheableRepositoryHelper); + CacheableRepositoryHelper cacheableRepositoryHelper, + MongoTemplate mongoTemplate) { + super(mongoOperations, mongoConverter, cacheableRepositoryHelper, mongoTemplate); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewPageRepositoryImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewPageRepositoryImpl.java index 370e5202b2..690b54d4c1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewPageRepositoryImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomNewPageRepositoryImpl.java @@ -2,6 +2,7 @@ package com.appsmith.server.repositories; import com.appsmith.server.repositories.ce.CustomNewPageRepositoryCEImpl; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.ReactiveMongoOperations; import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.stereotype.Component; @@ -13,7 +14,8 @@ public class CustomNewPageRepositoryImpl extends CustomNewPageRepositoryCEImpl i public CustomNewPageRepositoryImpl( ReactiveMongoOperations mongoOperations, MongoConverter mongoConverter, - CacheableRepositoryHelper cacheableRepositoryHelper) { - super(mongoOperations, mongoConverter, cacheableRepositoryHelper); + CacheableRepositoryHelper cacheableRepositoryHelper, + MongoTemplate mongoTemplate) { + super(mongoOperations, mongoConverter, cacheableRepositoryHelper, mongoTemplate); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java index c2d9b0634b..28d0012b85 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/BaseAppsmithRepositoryCEImpl.java @@ -22,6 +22,7 @@ import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.UpdateDefinition; +import org.springframework.data.mongodb.repository.Meta; import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.util.CollectionUtils; import reactor.core.publisher.Flux; @@ -166,7 +167,7 @@ public abstract class BaseAppsmithRepositoryCEImpl { return mongoOperations .query(this.genericDomain) - .matching(query) + .matching(query.cursorBatchSize(10000)) .one() .flatMap(obj -> setUserPermissionsInObject(obj, permissionGroups)); }); @@ -331,6 +332,7 @@ public abstract class BaseAppsmithRepositoryCEImpl { }); } + @Meta(cursorBatchSize = 10000) protected Mono queryOne( List criterias, List projectionFieldNames, Optional permission) { Mono> permissionGroupsMono = getCurrentUserPermissionGroupsIfRequired(permission); @@ -539,7 +541,7 @@ public abstract class BaseAppsmithRepositoryCEImpl { sortOptional.ifPresent(sort -> query.with(sort)); return mongoOperations .query(this.genericDomain) - .matching(query) + .matching(query.cursorBatchSize(10000)) .all() .flatMap(obj -> setUserPermissionsInObject(obj, permissionGroups)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java index 007ff409f8..11a6cb6af1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java @@ -78,7 +78,7 @@ public interface CustomNewActionRepositoryCE extends AppsmithRepository> bulkUpdate(List newActions); - Mono publishActions(String applicationId, AclPermission permission); + Mono> publishActions(String applicationId, AclPermission permission); Mono archiveDeletedUnpublishedActions(String applicationId, AclPermission permission); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java index 5a90b20dce..c45cf40bfa 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java @@ -20,9 +20,12 @@ import lombok.extern.slf4j.Slf4j; import org.bson.Document; import org.bson.types.ObjectId; import org.springframework.data.domain.Sort; +import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.ReactiveMongoOperations; import org.springframework.data.mongodb.core.aggregation.Aggregation; -import org.springframework.data.mongodb.core.aggregation.AggregationUpdate; +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; +import org.springframework.data.mongodb.core.aggregation.Fields; import org.springframework.data.mongodb.core.aggregation.GroupOperation; import org.springframework.data.mongodb.core.aggregation.MatchOperation; import org.springframework.data.mongodb.core.aggregation.ProjectionOperation; @@ -52,11 +55,15 @@ import static org.springframework.data.mongodb.core.query.Criteria.where; public class CustomNewActionRepositoryCEImpl extends BaseAppsmithRepositoryImpl implements CustomNewActionRepositoryCE { + private final MongoTemplate mongoTemplate; + public CustomNewActionRepositoryCEImpl( ReactiveMongoOperations mongoOperations, MongoConverter mongoConverter, - CacheableRepositoryHelper cacheableRepositoryHelper) { + CacheableRepositoryHelper cacheableRepositoryHelper, + MongoTemplate mongoTemplate) { super(mongoOperations, mongoConverter, cacheableRepositoryHelper); + this.mongoTemplate = mongoTemplate; } @Override @@ -571,16 +578,33 @@ public class CustomNewActionRepositoryCEImpl extends BaseAppsmithRepositoryImpl< } @Override - public Mono publishActions(String applicationId, AclPermission permission) { + public Mono> publishActions(String applicationId, AclPermission permission) { Criteria applicationIdCriteria = where(fieldName(QNewAction.newAction.applicationId)).is(applicationId); - // using aggregation update instead of regular update here - // it's required to set a field to a value of another field from the same domain - AggregationUpdate aggregationUpdate = AggregationUpdate.update() - .set(fieldName(QNewAction.newAction.publishedAction)) - .toValue("$" + fieldName(QNewAction.newAction.unpublishedAction)); - return updateByCriteria(List.of(applicationIdCriteria), aggregationUpdate, permission); + Mono> permissionGroupsMono = + getCurrentUserPermissionGroupsIfRequired(Optional.ofNullable(permission)); + + return permissionGroupsMono.flatMap(permissionGroups -> { + AggregationOperation matchAggregationWithPermission = null; + if (permission == null) { + matchAggregationWithPermission = Aggregation.match(new Criteria().andOperator(notDeleted())); + } else { + matchAggregationWithPermission = Aggregation.match( + new Criteria().andOperator(notDeleted(), userAcl(permissionGroups, permission))); + } + AggregationOperation matchAggregation = Aggregation.match(applicationIdCriteria); + AggregationOperation wholeProjection = Aggregation.project(NewAction.class); + AggregationOperation addFieldsOperation = Aggregation.addFields() + .addField(fieldName(QNewAction.newAction.publishedAction)) + .withValueOf(Fields.field(fieldName(QNewAction.newAction.unpublishedAction))) + .build(); + Aggregation combinedAggregation = Aggregation.newAggregation( + matchAggregation, matchAggregationWithPermission, wholeProjection, addFieldsOperation); + AggregationResults updatedResults = + mongoTemplate.aggregate(combinedAggregation, NewAction.class, NewAction.class); + return bulkUpdate(updatedResults.getMappedResults()); + }); } @Override diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java index dc940ee25b..ec6775c2cb 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java @@ -3,7 +3,7 @@ package com.appsmith.server.repositories.ce; import com.appsmith.server.acl.AclPermission; import com.appsmith.server.domains.NewPage; import com.appsmith.server.repositories.AppsmithRepository; -import com.mongodb.client.result.UpdateResult; +import com.mongodb.bulk.BulkWriteResult; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -43,5 +43,7 @@ public interface CustomNewPageRepositoryCE extends AppsmithRepository { Mono findByGitSyncIdAndDefaultApplicationId( String defaultApplicationId, String gitSyncId, Optional permission); - Mono publishPages(Collection pageIds, AclPermission permission); + Mono> publishPages(Collection pageIds, AclPermission permission); + + Mono> bulkUpdate(List newPages); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java index 92a93f963e..acd1a16e0f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java @@ -9,20 +9,32 @@ import com.appsmith.server.domains.QNewPage; import com.appsmith.server.dtos.PageDTO; import com.appsmith.server.repositories.BaseAppsmithRepositoryImpl; import com.appsmith.server.repositories.CacheableRepositoryHelper; -import com.mongodb.client.result.UpdateResult; +import com.mongodb.bulk.BulkWriteResult; +import com.mongodb.client.model.UpdateOneModel; +import com.mongodb.client.model.WriteModel; import lombok.extern.slf4j.Slf4j; +import org.bson.Document; +import org.bson.types.ObjectId; +import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.ReactiveMongoOperations; -import org.springframework.data.mongodb.core.aggregation.AggregationUpdate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; +import org.springframework.data.mongodb.core.aggregation.Fields; import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.util.CollectionUtils; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import static org.springframework.data.mongodb.core.query.Criteria.where; @@ -30,11 +42,15 @@ import static org.springframework.data.mongodb.core.query.Criteria.where; public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl implements CustomNewPageRepositoryCE { + private final MongoTemplate mongoTemplate; + public CustomNewPageRepositoryCEImpl( ReactiveMongoOperations mongoOperations, MongoConverter mongoConverter, - CacheableRepositoryHelper cacheableRepositoryHelper) { + CacheableRepositoryHelper cacheableRepositoryHelper, + MongoTemplate mongoTemplate) { super(mongoOperations, mongoConverter, cacheableRepositoryHelper); + this.mongoTemplate = mongoTemplate; } @Override @@ -251,14 +267,55 @@ public class CustomNewPageRepositoryCEImpl extends BaseAppsmithRepositoryImpl publishPages(Collection pageIds, AclPermission permission) { + public Mono> publishPages(Collection pageIds, AclPermission permission) { Criteria applicationIdCriteria = where(fieldName(QNewPage.newPage.id)).in(pageIds); - // using aggregation update instead of regular update here - // it's required to set a field to a value of another field from the same domain - AggregationUpdate aggregationUpdate = AggregationUpdate.update() - .set(fieldName(QNewPage.newPage.publishedPage)) - .toValue("$" + fieldName(QNewPage.newPage.unpublishedPage)); - return updateByCriteria(List.of(applicationIdCriteria), aggregationUpdate, permission); + Mono> permissionGroupsMono = + getCurrentUserPermissionGroupsIfRequired(Optional.ofNullable(permission)); + + return permissionGroupsMono.flatMap(permissionGroups -> { + AggregationOperation matchAggregationWithPermission = null; + if (permission == null) { + matchAggregationWithPermission = Aggregation.match(new Criteria().andOperator(notDeleted())); + } else { + matchAggregationWithPermission = Aggregation.match( + new Criteria().andOperator(notDeleted(), userAcl(permissionGroups, permission))); + } + AggregationOperation matchAggregation = Aggregation.match(applicationIdCriteria); + AggregationOperation wholeProjection = Aggregation.project(NewPage.class); + AggregationOperation addFieldsOperation = Aggregation.addFields() + .addField(fieldName(QNewPage.newPage.publishedPage)) + .withValueOf(Fields.field(fieldName(QNewPage.newPage.unpublishedPage))) + .build(); + Aggregation combinedAggregation = Aggregation.newAggregation( + matchAggregation, matchAggregationWithPermission, wholeProjection, addFieldsOperation); + AggregationResults updatedResults = + mongoTemplate.aggregate(combinedAggregation, NewPage.class, NewPage.class); + return bulkUpdate(updatedResults.getMappedResults()); + }); + } + + @Override + public Mono> bulkUpdate(List newPages) { + if (CollectionUtils.isEmpty(newPages)) { + return Mono.just(Collections.emptyList()); + } + + // convert the list of new pages to a list of DBObjects + List> dbObjects = newPages.stream() + .map(newPage -> { + assert newPage.getId() != null; + Document document = new Document(); + mongoOperations.getConverter().write(newPage, document); + document.remove("_id"); + return (WriteModel) new UpdateOneModel( + new Document("_id", new ObjectId(newPage.getId())), new Document("$set", document)); + }) + .collect(Collectors.toList()); + + return mongoOperations + .getCollection(mongoOperations.getCollectionName(NewPage.class)) + .flatMapMany(documentMongoCollection -> documentMongoCollection.bulkWrite(dbObjects)) + .collectList(); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java index e74852d3b5..505981ef1d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java @@ -3,12 +3,17 @@ package com.appsmith.server.repositories.ce; import com.appsmith.server.domains.NewAction; import com.appsmith.server.repositories.BaseRepository; import com.appsmith.server.repositories.CustomNewActionRepository; +import org.springframework.data.mongodb.repository.Meta; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; public interface NewActionRepositoryCE extends BaseRepository, CustomNewActionRepository { + @Meta(cursorBatchSize = 10000) Flux findByApplicationId(String applicationId); + @Meta(cursorBatchSize = 10000) + Flux findAllByIdIn(Iterable ids); + Mono countByDeletedAtNull(); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java index f34a9b9ab1..86be3f4383 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java @@ -50,6 +50,7 @@ import com.appsmith.server.solutions.ApplicationPermission; import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.WorkspacePermission; import com.google.common.base.Strings; +import com.mongodb.bulk.BulkWriteResult; import com.mongodb.client.result.UpdateResult; import jakarta.annotation.Nullable; import lombok.RequiredArgsConstructor; @@ -1146,7 +1147,7 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { if (isPublishedManually) { application.setLastDeployedAt(Instant.now()); } - Mono publishPagesMono = + Mono> publishPagesMono = newPageService.publishPages(editedPageIds, pagePermission.getEditPermission()); // Archive the deleted pages and save the application changes and then return the pages so that @@ -1156,7 +1157,7 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { }) .cache(); // caching as we'll need this to send analytics attributes after publishing the app - Mono publishActionsMono = + Mono> publishActionsMono = newActionService.publishActions(applicationId, actionPermission.getEditPermission()); // this is a map of pluginType to count of actions for that pluginType, required for analytics diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCE.java index cb480d23f3..b42c05c5fd 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCE.java @@ -7,7 +7,7 @@ import com.appsmith.server.domains.NewPage; import com.appsmith.server.dtos.ApplicationPagesDTO; import com.appsmith.server.dtos.PageDTO; import com.appsmith.server.services.CrudService; -import com.mongodb.client.result.UpdateResult; +import com.mongodb.bulk.BulkWriteResult; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -93,5 +93,5 @@ public interface NewPageServiceCE extends CrudService { Flux findPageSlugsByApplicationIds(List applicationIds, AclPermission aclPermission); - Mono publishPages(Collection pageIds, AclPermission permission); + Mono> publishPages(Collection pageIds, AclPermission permission); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java index 56466fd980..938e82179f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewPageServiceCEImpl.java @@ -23,7 +23,7 @@ import com.appsmith.server.services.BaseService; import com.appsmith.server.services.UserDataService; import com.appsmith.server.solutions.ApplicationPermission; import com.appsmith.server.solutions.PagePermission; -import com.mongodb.client.result.UpdateResult; +import com.mongodb.bulk.BulkWriteResult; import jakarta.validation.Validator; import lombok.extern.slf4j.Slf4j; import net.minidev.json.JSONObject; @@ -696,7 +696,7 @@ public class NewPageServiceCEImpl extends BaseService publishPages(Collection pageIds, AclPermission permission) { + public Mono> publishPages(Collection pageIds, AclPermission permission) { return repository.publishPages(pageIds, permission); } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java index 20ddd79e39..3a70e67def 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java @@ -24,7 +24,6 @@ import com.appsmith.server.solutions.ApplicationPermission; import com.appsmith.server.solutions.DatasourcePermission; import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PolicySolution; -import com.mongodb.client.result.UpdateResult; import io.micrometer.observation.ObservationRegistry; import jakarta.validation.Validator; import lombok.extern.slf4j.Slf4j; @@ -40,6 +39,8 @@ import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; import reactor.test.StepVerifier; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.anyString; @@ -200,9 +201,8 @@ public class NewActionServiceUnitTest { @Test public void testPublishActionArchivesAndPublishesActions() { String applicationId = "dummy-application-id"; - UpdateResult updateResult = Mockito.mock(UpdateResult.class); - Mockito.when(updateResult.getModifiedCount()).thenReturn(10L); - Mockito.when(updateResult.getMatchedCount()).thenReturn(5L); + List updateResult = Mockito.mock(List.class); + Mockito.when(updateResult.size()).thenReturn(10); Mockito.when(newActionRepository.archiveDeletedUnpublishedActions( applicationId, actionPermission.getEditPermission())) @@ -213,8 +213,7 @@ public class NewActionServiceUnitTest { StepVerifier.create(newActionService.publishActions(applicationId, actionPermission.getEditPermission())) .assertNext(updateResult1 -> { - assertEquals(10L, updateResult1.getModifiedCount()); - assertEquals(5L, updateResult1.getMatchedCount()); + assertEquals(10, updateResult1.size()); }) .verifyComplete(); }