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

chore: refactor theme import flow to support dry ops for pg #34733

Merged
merged 11 commits into from
Jul 24, 2024

Conversation

AnaghHegde
Copy link
Member

@AnaghHegde AnaghHegde commented Jul 4, 2024

Description

Please refer this document for more details - https://www.notion.so/appsmith/Transaction-Handling-in-PG-468cf8d4255749c3915699e59e91dc2f

Automation

/ok-to-test tags="@tag.Git, @tag.ImportExport, @tag.Templates"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10053864056
Commit: 0b83e89
Cypress dashboard.
Tags: @tag.Git, @tag.ImportExport, @tag.Templates
Spec:


Tue, 23 Jul 2024 06:45:31 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced import functionality to support themes and better handle applications.
  • Bug Fixes

    • Improved handling of application and theme imports in various scenarios, fixing related issues.
  • Tests

    • Updated test cases to validate the new and improved import functionality for themes and applications.

These changes improve the robustness and flexibility of application and theme management during imports.

@AnaghHegde AnaghHegde self-assigned this Jul 4, 2024
@AnaghHegde AnaghHegde requested a review from a team as a code owner July 4, 2024 15:42
Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Walkthrough

The recent updates enhance theme and application handling in the Appsmith server repository. They introduce new methods for saving, archiving, and updating themes and applications, ensuring better management and dry run operations for these entities. Additionally, imports and modifications in the test services align with these changes, ensuring comprehensive testing and integration.

Changes

File Path Change Summary
.../repositories/DryOperationRepository.java Added imports and methods for handling themes and applications including saveThemeToDb, archiveTheme, updateTheme, and updateApplication.
.../themes/importable/ThemeImportableServiceCEImpl.java Added imports and modified the importEntities method to handle theme updates and dry run operations.
.../dtos/ce/MappedImportableResourcesCE_DTO.java Added imports and fields for managing dry run queries for themes and applications.
.../tests/imports/internal/ImportServiceTests.java Modified methods related to importing themes and applications to ensure correct references and handling during imports.

Poem

In the world of code we tread,
Themes and apps now better fed.
With methods new, they thrive and bloom,
In the repository's vast room.
Testing, importing, all aligned,
Appsmith evolves, so refined. 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@AnaghHegde AnaghHegde removed the request for review from a team July 4, 2024 15:42
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jul 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 52e8cda and a8b1181.

Files selected for processing (5)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/MappedImportableResourcesCE_DTO.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (5 hunks)
Additional comments not posted (13)
app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/MappedImportableResourcesCE_DTO.java (2)

5-7: New imports added for Application and Theme

The imports for Application and Theme are necessary for the new attributes in the class.


56-58: New attributes added for dry run queries

The new attributes themeDryRunQueries and applicationDryRunQueries are maps that store lists of Theme and Application objects, respectively. These attributes will help manage dry run operations for themes and applications.

app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCE.java (1)

64-65: New method signature added for getOrSaveTheme

The new method signature getOrSaveTheme includes an additional boolean isDryOps parameter to handle dry run operations. This change is consistent with the PR objective to support dry operations.

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java (4)

5-8: New imports added for AclPermission, Application, Theme, and DBOpsType

The imports for AclPermission, Application, Theme, and DBOpsType are necessary for the new methods and modifications in the class.


30-35: New dependencies added

The new dependencies ThemeRepository, ThemeService, and ApplicationRepository are necessary for managing themes and applications in the new methods.


59-74: New methods for managing themes and applications

The new methods saveThemeToDb, archiveTheme, updateTheme, and updateApplication handle theme and application operations. These methods are crucial for the new dry run operations.


97-134: Modifications to executeAllDbOps method

The executeAllDbOps method has been enhanced to support theme and application operations. The new logic handles saving, updating, and archiving themes and applications during dry run operations.

app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (4)

Line range hint 9-22:
New imports added for DBOpsType, ArrayList, List, and Map

The imports for DBOpsType, ArrayList, List, and Map are necessary for the new methods and modifications in the class.


Line range hint 77-103:
Modifications to importEntities method

The importEntities method has been modified to handle theme updates and dry run operations. This change is consistent with the PR objective to support dry operations.


110-160: New logic for updating themes from JSON

The new logic in the updateExistingAppThemeFromJSON method handles dry run operations for themes. This includes saving, updating, and deleting themes based on the dry run operations.


182-189: New methods for managing dry run operations

The new methods addDryOpsForEntity and addDryOpsForApplication manage dry run operations for themes and applications. These methods are crucial for the new dry run operations.

app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java (2)

436-437: Ensure correct usage of the new method.

The existing method getOrSaveTheme now calls the new method with isDryOps set to false. This change appears correct.


Line range hint 439-461:
Verify the handling of the isDryOps parameter.

The new implementation correctly handles the isDryOps parameter by updating the theme for bulk write operations without saving it to the repository when isDryOps is true. This change appears correct.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a8b1181 and b8727db.

Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (5 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java

Copy link

github-actions bot commented Jul 5, 2024

Failed server tests

  • com.appsmith.server.imports.internal.ImportServiceTests#importApplicationInWorkspace_WhenCustomizedThemes_ThemesCreated
  • com.appsmith.server.imports.internal.ImportServiceTests#importApplication_WhenUpdateLayoutFailures_Success
  • com.appsmith.server.imports.internal.ImportServiceTests#importApplication_withUnConfiguredDatasources_Success
  • com.appsmith.server.imports.internal.ImportServiceTests#importArtifactFromValidJsonFileTest
  • com.appsmith.server.imports.internal.ImportServiceTests#importArtifact_WithoutThemes_LegacyThemesAssigned
  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_ApplicationThemeNotFound_DefaultThemeImported
  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_WhenBothImportedThemesAreCustom_NewThemesCreated

Copy link

github-actions bot commented Jul 9, 2024

Failed server tests

  • com.appsmith.server.imports.internal.ImportServiceTests#importApplicationInWorkspace_WhenCustomizedThemes_ThemesCreated
  • com.appsmith.server.imports.internal.ImportServiceTests#importApplication_WhenUpdateLayoutFailures_Success
  • com.appsmith.server.imports.internal.ImportServiceTests#importApplication_withUnConfiguredDatasources_Success
  • com.appsmith.server.imports.internal.ImportServiceTests#importArtifactFromValidJsonFileTest
  • com.appsmith.server.imports.internal.ImportServiceTests#importArtifact_WithoutThemes_LegacyThemesAssigned
  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_ApplicationThemeNotFound_DefaultThemeImported
  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_WhenBothImportedThemesAreCustom_NewThemesCreated

@AnaghHegde AnaghHegde added the ok-to-test Required label for CI label Jul 9, 2024
@appsmithorg appsmithorg deleted a comment from github-actions bot Jul 9, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b8727db and 0a5932e.

Files selected for processing (4)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (5 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (5 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ThemeImportableServiceCETest.java (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java
Additional comments not posted (13)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ThemeImportableServiceCETest.java (8)

32-32: Ensure the usage of @DirtiesContext is necessary.

The @DirtiesContext annotation is typically used to indicate that the context should be reset after a test method. Ensure that this is necessary for the test cases in this file, as it can slow down test execution.


43-43: Verify the necessity of @DirtiesContext at the class level.

Using @DirtiesContext at the class level will cause the Spring context to be reset after each test method, which can significantly increase test execution time. Ensure this is required for the tests in this class.


172-174: Initialization of new DTO variables.

The new variables MappedImportableResourcesDTO and ImportingMetaDTO are initialized but not used until later in the method. Ensure that their initialization is necessary at this point.


175-185: Updated method logic for importing themes.

The method now uses MappedImportableResourcesDTO and ImportingMetaDTO to handle the import process. Ensure that the logic correctly manages theme dry run queries and that the thenReturn statement accurately reflects the intended behavior.


186-196: Assertions for theme dry run queries.

The assertions check that two themes are saved and that their IDs are different. Ensure that these assertions accurately reflect the expected behavior and that the themes are correctly processed during the import.


212-214: Initialization of new DTO variables.

The new variables MappedImportableResourcesDTO and ImportingMetaDTO are initialized but not used until later in the method. Ensure that their initialization is necessary at this point.


Line range hint 220-239:
Updated method logic for importing themes.

The method now uses MappedImportableResourcesDTO and ImportingMetaDTO to handle the import process. Ensure that the logic correctly manages theme dry run queries and that the thenReturn statement accurately reflects the intended behavior.


241-246: Assertions for theme dry run queries.

The assertions check that the default theme is correctly set for both edit mode and published mode. Ensure that these assertions accurately reflect the expected behavior and that the themes are correctly processed during the import.

app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (5)

978-980: Verify tuple element access for application details.

Ensure that accessing the application details directly from tuple.getT7() is correct and that it aligns with the expected structure of the tuple.


1135-1137: Verify tuple element access for application details.

Ensure that accessing the application details directly from importDTO.getApplication() is correct and that it aligns with the expected structure of the tuple.


1293-1297: Verify tuple element access for application details.

Ensure that accessing the application details directly from applicationImportDTO.getApplication().getId() is correct and that it aligns with the expected structure of the tuple.


1515-1517: Verify tuple element access for application details.

Ensure that accessing the application details directly from applicationImportDTO.getApplication().getId() is correct and that it aligns with the expected structure of the tuple.


5272-5274: Verify tuple element access for application details.

Ensure that accessing the application details directly from applicationImportDTO.getApplication().getId() is correct and that it aligns with the expected structure of the tuple.

Copy link

github-actions bot commented Jul 9, 2024

Failed server tests

  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_ApplicationThemeNotFound_DefaultThemeImported
  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_WhenBothImportedThemesAreCustom_NewThemesCreated

1 similar comment
Copy link

github-actions bot commented Jul 9, 2024

Failed server tests

  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_ApplicationThemeNotFound_DefaultThemeImported
  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_WhenBothImportedThemesAreCustom_NewThemesCreated

@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 9, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0a5932e and 8c1e065.

Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java

Copy link
Contributor

@abhvsn abhvsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnaghHegde now that we have encountered the update and save ops, how are we making sure we are making these DB ops in chronological order? Even better can we find the final object that comes out of the service layer and stick to save DB call?


Map<String, List<Theme>> themeDryRunQueries = new HashMap<>();

Map<String, List<Application>> applicationDryRunQueries = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we expecting the value as List<Application> in any of the flows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhvsn At this movement its just only one update, but once i move to refactoring the entities like page, application we will have multiple updates of application object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's where this comment coming from. Considering this will be the same object instead of creating multiple entries can we just keep updating the existing application object. That way # of db ops will be reduced and also we will not face any issue around data loss because of overwriting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point but i am worried that due to parallel executions we might miss some updates. Hence i decided to keep this as list. And when we use bulk update we will not face much issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnaghHegde after todays update are we aligned on keeping this as a single application instead of list of application?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhvsn Yes correct, this will be updated but i will do this in page import PR. The current flow has only instance of application in the list.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8c1e065 and e5e6cb3.

Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java (5 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e5e6cb3 and 334ea3d.

Files selected for processing (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/MappedImportableResourcesCE_DTO.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java (4 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (5 hunks)
Files skipped from review due to trivial changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/MappedImportableResourcesCE_DTO.java
Files skipped from review as they are similar to previous changes (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/DryOperationRepository.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java

Copy link

Failed server tests

  • com.appsmith.server.services.ce.ApplicationServiceCETest#invalidUpdateApplication

@AnaghHegde AnaghHegde requested a review from abhvsn July 10, 2024 09:44
@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 10, 2024
Copy link
Contributor

@abhvsn abhvsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added minor comments but just wanted to refer that we are not updating the existing application object from artifactImportDTO instead we are creating a new list of application, which may lead to unintended behaviour.

Copy link

Failed server tests

  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_WhenBothImportedThemesAreCustom_NewThemesCreated

1 similar comment
Copy link

Failed server tests

  • com.appsmith.server.services.ce.ThemeImportableServiceCETest#importThemesToApplication_WhenBothImportedThemesAreCustom_NewThemesCreated

@AnaghHegde AnaghHegde requested a review from abhvsn July 23, 2024 06:25
@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 23, 2024
@AnaghHegde AnaghHegde merged commit b1ff50b into release Jul 24, 2024
42 checks passed
@AnaghHegde AnaghHegde deleted the pg-transaction-theme-import-flow branch July 24, 2024 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants