Skip to content

Commit

Permalink
removed lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
sondermanish committed May 23, 2024
1 parent e1adbc5 commit 5cf5e31
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -308,6 +309,46 @@ public Mono<Map<String, Integer>> 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<Integer> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,25 +19,20 @@

@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<Boolean> isServerAutoCommitRequired(String workspaceId, GitArtifactMetadata gitMetadata) {

String defaultApplicationId = gitMetadata.getDefaultArtifactId();
String branchName = gitMetadata.getBranchName();
String repoName = gitMetadata.getRepoName();

return commonGitService
return commonGitFileUtils
.getMetadataServerSchemaMigrationVersion(
workspaceId, defaultApplicationId, branchName, repoName, ArtifactType.APPLICATION)
.map(serverSchemaVersion -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,4 @@ Mono<List<String>> updateProtectedBranches(
Mono<AutoCommitProgressDTO> getAutoCommitProgress(String applicationId, ArtifactType artifactType);

Mono<Boolean> autoCommitApplication(String defaultApplicationId, String branchName, ArtifactType artifactType);

Mono<Integer> getMetadataServerSchemaMigrationVersion(
String workspaceId,
String defaultArtifactId,
String branchName,
String repoName,
ArtifactType artifactType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3492,46 +3490,4 @@ protected Mono<Void> 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<Integer> 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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class AutoCommitEligibilityHelperTest {
AutoCommitEligibiltyHelper autoCommitEligibiltyHelper;

@SpyBean
CommonGitService commonGitService;
CommonGitFileUtils commonGitFileUtils;

@MockBean
DSLMigrationUtils dslMigrationUtils;
Expand Down Expand Up @@ -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));

Expand All @@ -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));

Expand Down

0 comments on commit 5cf5e31

Please sign in to comment.