From 5cf5e312db4a370113341906d55cc4f4efed175f Mon Sep 17 00:00:00 2001 From: sondermanish Date: Thu, 23 May 2024 17:08:18 +0530 Subject: [PATCH] removed lazy loading --- .../helpers/ce/CommonGitFileUtilsCE.java | 41 +++++++++++++++++ .../AutoCommitEligibilityHelperImpl.java | 15 +++---- .../services/ce/CommonGitServiceCE.java | 7 --- .../services/ce/CommonGitServiceCEImpl.java | 44 ------------------- .../AutoCommitEligibilityHelperTest.java | 8 ++-- 5 files changed, 50 insertions(+), 65 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java index e5c2b879167..55de15718a8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java @@ -40,6 +40,7 @@ import static com.appsmith.git.constants.CommonConstants.CLIENT_SCHEMA_VERSION; import static com.appsmith.git.constants.CommonConstants.FILE_FORMAT_VERSION; import static com.appsmith.git.constants.CommonConstants.SERVER_SCHEMA_VERSION; +import static org.springframework.util.StringUtils.hasText; @Slf4j @RequiredArgsConstructor @@ -308,6 +309,46 @@ public Mono> reconstructMetadataFromRepo( }); } + /** + * Provides the server schema version in the application json for the given branch + * + * @param workspaceId : workspaceId of the artifact + * @param defaultArtifactId : default branch id of the artifact + * @param branchName : current branch name of the artifact + * @param repoName : repository name + * @param artifactType : artifact type of this operation + * @return the server schema migration version number + */ + public Mono getMetadataServerSchemaMigrationVersion( + String workspaceId, + String defaultArtifactId, + String branchName, + String repoName, + ArtifactType artifactType) { + + if (!hasText(workspaceId)) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.WORKSPACE_ID)); + } + + if (!hasText(defaultArtifactId)) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ARTIFACT_ID)); + } + + if (!hasText(branchName)) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.BRANCH_NAME)); + } + + if (!hasText(repoName)) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.REPO_NAME)); + } + + return reconstructMetadataFromRepo(workspaceId, defaultArtifactId, branchName, repoName, artifactType) + .map(metadataMap -> { + return metadataMap.getOrDefault( + CommonConstants.SERVER_SCHEMA_VERSION, JsonSchemaVersions.serverVersion); + }); + } + private Integer getServerSchemaVersion(JsonObject metadataJsonObject) { if (metadataJsonObject == null) { return JsonSchemaVersions.serverVersion; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperImpl.java index 9e9a9e0dc50..f086ef997df 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperImpl.java @@ -4,13 +4,13 @@ import com.appsmith.server.domains.GitArtifactMetadata; import com.appsmith.server.domains.Layout; import com.appsmith.server.dtos.PageDTO; +import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.DSLMigrationUtils; import com.appsmith.server.helpers.GitUtils; import com.appsmith.server.migrations.JsonSchemaVersions; -import com.appsmith.server.services.CommonGitService; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import net.minidev.json.JSONObject; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @@ -19,17 +19,12 @@ @Slf4j @Component +@RequiredArgsConstructor public class AutoCommitEligibilityHelperImpl implements AutoCommitEligibiltyHelper { - private final CommonGitService commonGitService; + private final CommonGitFileUtils commonGitFileUtils; private final DSLMigrationUtils dslMigrationUtils; - public AutoCommitEligibilityHelperImpl( - @Lazy CommonGitService commonGitService, DSLMigrationUtils dslMigrationUtils) { - this.commonGitService = commonGitService; - this.dslMigrationUtils = dslMigrationUtils; - } - @Override public Mono isServerAutoCommitRequired(String workspaceId, GitArtifactMetadata gitMetadata) { @@ -37,7 +32,7 @@ public Mono isServerAutoCommitRequired(String workspaceId, GitArtifactM String branchName = gitMetadata.getBranchName(); String repoName = gitMetadata.getRepoName(); - return commonGitService + return commonGitFileUtils .getMetadataServerSchemaMigrationVersion( workspaceId, defaultApplicationId, branchName, repoName, ArtifactType.APPLICATION) .map(serverSchemaVersion -> { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCE.java index 073bedb2f1a..c7cca9e12ad 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCE.java @@ -107,11 +107,4 @@ Mono> updateProtectedBranches( Mono getAutoCommitProgress(String applicationId, ArtifactType artifactType); Mono autoCommitApplication(String defaultApplicationId, String branchName, ArtifactType artifactType); - - Mono getMetadataServerSchemaMigrationVersion( - String workspaceId, - String defaultArtifactId, - String branchName, - String repoName, - ArtifactType artifactType); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java index 4e8989680b4..11add1027d3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java @@ -9,7 +9,6 @@ import com.appsmith.external.git.GitExecutor; import com.appsmith.external.git.constants.GitConstants; import com.appsmith.external.git.constants.GitSpan; -import com.appsmith.git.constants.CommonConstants; import com.appsmith.server.acl.AclPermission; import com.appsmith.server.configurations.EmailConfig; import com.appsmith.server.constants.ArtifactType; @@ -44,7 +43,6 @@ import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.helpers.ce.autocommit.GitAutoCommitHelper; import com.appsmith.server.imports.internal.ImportService; -import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.repositories.GitDeployKeysRepository; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.GitArtifactHelper; @@ -3492,46 +3490,4 @@ protected Mono sendBranchProtectionAnalytics( return Flux.merge(eventSenderMonos).then(); } - - /** - * Provides the server schema version in the application json for the given branch - * - * @param workspaceId : workspaceId of the artifact - * @param defaultArtifactId : default branch id of the artifact - * @param branchName : current branch name of the artifact - * @param repoName : repository name - * @param artifactType : artifact type of this operation - * @return the server schema migration version number - */ - @Override - public Mono getMetadataServerSchemaMigrationVersion( - String workspaceId, - String defaultArtifactId, - String branchName, - String repoName, - ArtifactType artifactType) { - - if (!hasText(workspaceId)) { - return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.WORKSPACE_ID)); - } - - if (!hasText(defaultArtifactId)) { - return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ARTIFACT_ID)); - } - - if (!hasText(branchName)) { - return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.BRANCH_NAME)); - } - - if (!hasText(repoName)) { - return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.REPO_NAME)); - } - - return commonGitFileUtils - .reconstructMetadataFromRepo(workspaceId, defaultArtifactId, branchName, repoName, artifactType) - .map(metadataMap -> { - return metadataMap.getOrDefault( - CommonConstants.SERVER_SCHEMA_VERSION, JsonSchemaVersions.serverVersion); - }); - } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperTest.java index 2d62bc41d4e..3e4779832dc 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ce/autocommit/AutoCommitEligibilityHelperTest.java @@ -4,9 +4,9 @@ import com.appsmith.server.domains.GitArtifactMetadata; import com.appsmith.server.domains.Layout; import com.appsmith.server.dtos.PageDTO; +import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.DSLMigrationUtils; import com.appsmith.server.migrations.JsonSchemaVersions; -import com.appsmith.server.services.CommonGitService; import lombok.extern.slf4j.Slf4j; import net.minidev.json.JSONObject; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ public class AutoCommitEligibilityHelperTest { AutoCommitEligibiltyHelper autoCommitEligibiltyHelper; @SpyBean - CommonGitService commonGitService; + CommonGitFileUtils commonGitFileUtils; @MockBean DSLMigrationUtils dslMigrationUtils; @@ -169,7 +169,7 @@ public void isServerMigrationRequired_WhenJsonSchemaIsNotAhead_ReturnsFalse() { gitArtifactMetadata.setRepoName(repoName); gitArtifactMetadata.setBranchName(branchName); - Mockito.when(commonGitService.getMetadataServerSchemaMigrationVersion( + Mockito.when(commonGitFileUtils.getMetadataServerSchemaMigrationVersion( workspaceId, defaultApplicationId, branchName, repoName, ArtifactType.APPLICATION)) .thenReturn(Mono.just(JsonSchemaVersions.serverVersion)); @@ -195,7 +195,7 @@ public void isServerMigrationRequired_WhenJsonSchemaIsAhead_ReturnsTrue() { gitArtifactMetadata.setRepoName(repoName); gitArtifactMetadata.setBranchName(branchName); - Mockito.when(commonGitService.getMetadataServerSchemaMigrationVersion( + Mockito.when(commonGitFileUtils.getMetadataServerSchemaMigrationVersion( workspaceId, defaultApplicationId, branchName, repoName, ArtifactType.APPLICATION)) .thenReturn(Mono.just(JsonSchemaVersions.serverVersion - 1));