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

fix: skipped unnecessary code for js object updates #37125

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

sneha122
Copy link
Contributor

@sneha122 sneha122 commented Oct 29, 2024

Description

This PR is in continuation to PR which we had merged earlier, In previous, we skipped the redundant calls to update page layout when updating each js object action, as we already have a call for updating the page layout for actionCollection

Since we have skipped the update page layout for each js action, we no longer need the code part after this, which basically fetches page data from DB and updates the errorReports in actionDTO based on layout layoutOnLoadActionErrors. This PR skips this unnecessary part too for each js action as we do set the errorReport for actionCollection in the end

Will this have any impact on error messages shown to user?

In order to understand this, checked out the frontend code to see if errorReports from individual js action is getting consumed on updating js object, looks like it is not, so we can safely remove this piece of code.
However this points to existing bug in the code (as errorReports is not even getting consumed from actionCollection), which is, when there is cyclic dependency created for js object with a widget, we don't get any toast message. Since this is existing issue which is not caused by any of the above PR implementations, creating separate issue for it and tracking it here

Fixes #37114
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.JS, @tag.JS"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11698258739
Commit: 9fbde99
Cypress dashboard.
Tags: @tag.JS, @tag.JS
Spec:


Wed, 06 Nov 2024 06:50:05 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Streamlined layout update process for actions, enhancing performance and clarity.
  • Bug Fixes

    • Improved test reliability by monitoring interactions with the layout service and handling cyclic dependencies.
  • Documentation

    • Updated comments to clarify the logic behind layout updates for JS actions.
  • Tests

    • Enhanced test descriptions and assertions for better clarity and validation of method interactions, including cyclic dependency scenarios.

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

The changes made in this pull request focus on the LayoutActionServiceCEImpl class, specifically the updateActionBasedOnContextType method, simplifying the logic for updating page layouts based on action types. It distinguishes between JavaScript actions and other action types, streamlining the process. Additionally, modifications were made to the ActionCollectionServiceTest class to enhance testing by renaming a test method for clarity and adding assertions to verify cyclic dependency error handling.

Changes

File Change Summary
.../LayoutActionServiceCEImpl.java Updated updateActionBasedOnContextType method to simplify layout update logic for JS and non-JS actions. Comments updated for clarity.
.../ActionCollectionServiceTest.java Renamed test method to reflect broader scope and included assertions for cyclic dependency errors. Updated test logic for action setup.

Assessment against linked issues

Objective Addressed Explanation
Add metrics for uninstrumented time during action update (#37114) No metrics were added in this PR as per the issue.

Possibly related PRs

Suggested reviewers

  • Nidhi Nair
  • Nilansh Bansal

🎉 In the realm of code where logic flows,
A method transformed, as clarity grows.
JS actions now swift, their path is clear,
While tests stand guard, with metrics near.
Cheers to the changes, let progress unfold,
In the world of code, new stories are told! 🎊


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@github-actions github-actions bot added Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Product Issues related to a specific integration Javascript Product Issues related to users writing javascript in appsmith JS Objects Issues related to JS Objects Query & JS Pod Issues related to the query & JS Pod Task A simple Todo labels Oct 29, 2024
@sneha122 sneha122 added ok-to-test Required label for CI and removed Task A simple Todo JS Objects Issues related to JS Objects Javascript Product Issues related to users writing javascript in appsmith Query & JS Pod Issues related to the query & JS Pod Integrations Product Issues related to a specific integration Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. labels Oct 29, 2024
@github-actions github-actions bot added Bug Something isn't working Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Product Issues related to a specific integration Javascript Product Issues related to users writing javascript in appsmith JS Objects Issues related to JS Objects Query & JS Pod Issues related to the query & JS Pod Task A simple Todo labels Oct 29, 2024
@github-actions github-actions bot added Query & JS Pod Issues related to the query & JS Pod Task A simple Todo labels Oct 29, 2024
@sneha122 sneha122 marked this pull request as ready for review October 30, 2024 06:57
@sneha122 sneha122 requested review from NilanshBansal and removed request for nidhi-nair and sondermanish October 30, 2024 06:58
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: 2

🧹 Outside diff range and nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java (1)

280-283: Consider using structured logging.

The debug log could be improved by using structured logging with key-value pairs.

-log.debug(
-        "Update action based on context type completed, returning actionDTO with action id: {}",
-        actionDTO != null ? actionDTO.getId() : null);
+log.debug("Update action based on context type completed, actionId={}", 
+        actionDTO != null ? actionDTO.getId() : "null");
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d6305ba and cdd2e38.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (3 hunks)
🔇 Additional comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java (1)

253-257: LGTM! Clear explanation in the comment.

The comment effectively explains why page layout updates are skipped for JS actions, which aligns with the PR objectives of removing redundant operations.

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (2)

97-97: LGTM! Good use of @SpyBean for method verification.

The change from @Autowired to @SpyBean enables proper verification of method calls while maintaining real method behavior.


Line range hint 711-776: LGTM! Clear test method name and well-documented verifications.

The test method now:

  1. Has a more descriptive name that clearly states its purpose
  2. Properly verifies the number of method calls
  3. Includes clear comments explaining the expected call counts

@sneha122 sneha122 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Nov 5, 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

🧹 Outside diff range and nitpick comments (3)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (3)

712-713: Consider simplifying the test method name for readability.

The method name testUpdateUnpublishedActionCollection_withValidCollection_callsPageLayoutOnlyOnceAndAssertCyclicDependencyError is quite long. Shortening it might improve readability while still conveying the purpose of the test.


749-758: Add checks before accessing list elements to prevent exceptions.

When calling dslList.get(0), ensure the list is not empty to avoid IndexOutOfBoundsException. Adding a check will make the test more robust.


773-777: Simplify action retrieval in the stream operation.

Instead of streaming and filtering to find testAction1, consider storing a direct reference when creating the action. This will make the code clearer and more efficient.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cdd2e38 and ed54f78.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (5 hunks)
🔇 Additional comments (1)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (1)

791-795: Assertions correctly validate the cyclic dependency error.

The test accurately checks for the presence of the cyclic dependency error, ensuring the error handling logic is functioning as intended.

Copy link
Contributor

@NilanshBansal NilanshBansal left a comment

Choose a reason for hiding this comment

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

Added comments.

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

🧹 Outside diff range and nitpick comments (1)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (1)

793-803: Consider adding specific error message assertion.

While the code verifies the error code, it would be valuable to also assert the specific error message to ensure complete error reporting.

 assertEquals(
         AppsmithError.CYCLICAL_DEPENDENCY_ERROR.getAppErrorCode(),
         actionCollectionDTO1.getErrorReports().get(0).getCode());
+assertEquals(
+        "Cyclic dependency found in Table1. Please resolve it.",
+        actionCollectionDTO1.getErrorReports().get(0).getMessage());
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ed54f78 and 9fbde99.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (6 hunks)
🔇 Additional comments (3)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java (3)

713-714: LGTM! Clear and descriptive test method name.

The renamed method accurately describes its purpose of testing page layout calls and cyclic dependency error handling.


750-765: LGTM! Well-structured test data setup.

The table DSL setup with dynamic binding to testCollection1.testAction1.data creates the foundation for testing cyclic dependencies.


773-778: LGTM! Clear cyclic dependency creation.

The code effectively creates a cyclic dependency by making testAction1 return Table1.tableData, while the table depends on the action's data.

Copy link
Contributor

@NilanshBansal NilanshBansal left a comment

Choose a reason for hiding this comment

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

LGTM

@sneha122 sneha122 merged commit 756dc54 into release Nov 6, 2024
43 checks passed
@sneha122 sneha122 deleted the fix/skip-redudant-code-from-js-object-update branch November 6, 2024 07:25
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
## Description

This PR is in continuation to
[PR](appsmithorg#37062) which we had
merged earlier, In previous, we skipped the redundant calls to update
page layout when updating each js object action, as we already have a
call for [updating the page layout for
actionCollection](https://github.com/appsmithorg/appsmith/blob/27bdeb92b6a0b27e6afcbfe80a5cb0705c0812ac/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutCollectionServiceCEImpl.java#L411)

Since we have skipped the update page layout for each js action, we no
longer need the code part after this, which basically fetches page data
from DB and updates the `errorReports` in actionDTO based on layout
`layoutOnLoadActionErrors`. This PR skips this unnecessary part too for
each js action as we do [set the errorReport for actionCollection in the
end](https://github.com/appsmithorg/appsmith/blob/27bdeb92b6a0b27e6afcbfe80a5cb0705c0812ac/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutCollectionServiceCEImpl.java#L430)

### Will this have any impact on error messages shown to user?
In order to understand this, checked out the frontend code to see if
errorReports from individual js action is getting consumed on updating
js object, looks like [it is
not](https://github.com/appsmithorg/appsmith/blob/e7e3d5e00290919c1df0767fdefed67458ec3cc9/app/client/src/sagas/JSPaneSagas.ts#L316),
so we can safely remove this piece of code.
However this points to existing bug in the code (as errorReports is not
even getting consumed from actionCollection), which is, when there is
cyclic dependency created for js object with a widget, we don't get any
toast message. Since this is existing issue which is not caused by any
of the above PR implementations, creating separate issue for it and
tracking it [here](appsmithorg#37129)

Fixes appsmithorg#37114 
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.JS, @tag.JS"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11698258739>
> Commit: 9fbde99
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11698258739&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS, @tag.JS`
> Spec:
> <hr>Wed, 06 Nov 2024 06:50:05 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Streamlined layout update process for actions, enhancing performance
and clarity.

- **Bug Fixes**
- Improved test reliability by monitoring interactions with the layout
service and handling cyclic dependencies.

- **Documentation**
- Updated comments to clarify the logic behind layout updates for JS
actions.

- **Tests**
- Enhanced test descriptions and assertions for better clarity and
validation of method interactions, including cyclic dependency
scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: “sneha122” <“sneha@appsmith.com”>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Product Issues related to a specific integration Javascript Product Issues related to users writing javascript in appsmith JS Objects Issues related to JS Objects ok-to-test Required label for CI Query & JS Pod Issues related to the query & JS Pod Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Add metrics for uninstrumented time during action update
3 participants