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: removed redundant page DB calls from js action creation flow #37668

Open
wants to merge 1 commit into
base: release
Choose a base branch
from

Conversation

sneha122
Copy link
Contributor

@sneha122 sneha122 commented Nov 25, 2024

Description

During action creation flow, page is fetched twice (making two independent DB calls) and taking significant time, this PR makes only 1 page DB call and passes the page object to subsequent calls, instead of fetching page again.

Fixes #37567
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.Datasource"

🔍 Cypress test results

Tip

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


Mon, 25 Nov 2024 06:20:08 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced action creation process with the introduction of a new parameter for improved functionality.
    • Optimized cloning of applications and pages by reducing redundant database calls.
  • Bug Fixes

    • Ensured proper handling of the executeOnLoad property during action creation in cloning contexts.
  • Tests

    • Updated tests to reflect changes in action creation logic and verify new behaviors.

Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the createAction method across several classes in the application. An additional parameter has been introduced to the method signature, allowing for enhanced functionality during action creation. This parameter is currently set to null but is intended to optimize the process by potentially reducing database calls and improving efficiency. The overall control flow and error handling within the affected methods remain consistent with previous implementations.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/fork/internal/ApplicationForkingServiceCEImpl.java Updated forkApplications method to include an additional parameter in layoutActionService.createAction.
app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/clonepage/ActionClonePageServiceCEImpl.java Modified cloneEntities method to add a new parameter in the createAction call.
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java Updated createAction method signature to include a new parameter, NewPage newPage.
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java Multiple updates to createAction and validateAndGenerateActionDomainBasedOnContext methods to incorporate the new NewPage parameter.
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ActionServiceCE_Test.java Updated test method to reflect changes in createAction method signature and verify new behavior.

Assessment against linked issues

Objective Addressed Explanation
Optimize page fetch time during JS object action creation (#37567)

Possibly related PRs

Suggested labels

Bug, Task, JS Objects, Javascript Product, Query & JS Pod, Integrations Product, Integrations Pod General, ok-to-test

Suggested reviewers

  • nidhi-nair
  • sondermanish
  • subrata71

🎉 In the land of code where actions play,
A new parameter joins the fray!
With createAction now more spry,
Cloning pages, oh my, oh my!
Efficiency blooms, like flowers in May,
Cheers to the changes, hip-hip-hooray! 🎈


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 Query & JS Pod Issues related to the query & JS Pod Task A simple Todo labels Nov 25, 2024
@sneha122 sneha122 added the ok-to-test Required label for CI label Nov 25, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 25, 2024
@sneha122
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12003842608.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37668.
recreate: .

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: 1

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

1183-1183: LGTM! Consider documenting the new parameter.

The addition of the null parameter aligns with the PR objective to optimize page fetch time. However, the purpose of this parameter could be clearer.

Consider adding a comment explaining the purpose of the null parameter in the context of page fetch optimization.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a320605 and 9297770.

📒 Files selected for processing (5)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/fork/internal/ApplicationForkingServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/clonepage/ActionClonePageServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java (3 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ActionServiceCE_Test.java (1 hunks)
🔇 Additional comments (9)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java (5)

341-342: Correct permission assignment based on action type.


345-350: Efficient reuse of newPage to eliminate redundant database calls.


354-356: Overloaded createAction method enhances performance by accepting newPage.


360-363: Optimizing method calls by passing newPage.


Line range hint 420-438: Streamlined page retrieval in validateAndGenerateActionDomainBasedOnContext.

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java (2)

5-5: LGTM!

Clean import addition following the existing import organization pattern.


27-28: Verify implementation of the new parameter across all service implementations

The interface change aligns with the optimization goal of reducing redundant page fetches. However, ensure that implementing classes are making effective use of the newPage parameter rather than passing null, which would defeat the optimization purpose.

✅ Verification successful

The previous pattern didn't work well with ast-grep, so I'm using ripgrep with more specific patterns to:

  1. Find actual implementations of the createAction method with the new parameter
  2. Find classes that implement or extend LayoutActionService
    This will help us verify how the new parameter is being used across implementations.

Now let's examine the actual implementation to see how the newPage parameter is being used in both the CE implementation and the main implementation.


Let's try a simpler pattern to see the method implementations and how they use the newPage parameter.


Implementation correctly utilizes the newPage parameter

The implementation in LayoutActionServiceCEImpl properly uses the newPage parameter in the validateAndGenerateActionDomainBasedOnContext call, and there's no evidence of null being passed. The parameter flows through the service hierarchy as intended, supporting the optimization goal.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for implementations passing null for the newPage parameter
ast-grep --pattern 'createAction($_, $_, $_, null)'

# Find all implementations of this interface
ast-grep --pattern 'class $_ implements $$$LayoutActionServiceCE'

Length of output: 121


Script:

#!/bin/bash
# Search for implementations of createAction method
rg -U "createAction\(.*?\bActionDTO\b.*?\bAppsmithEventContext\b.*?\bBoolean\b.*?\bNewPage\b.*?\)" -g "*.java" -A 5

# Find all classes that implement or extend LayoutActionService
rg "class\s+\w+(?:CE|Impl)?\s+(?:implements|extends)\s+.*?LayoutActionService.*?" -g "*.java"

Length of output: 594


Script:

#!/bin/bash
# Look for the implementation of createAction in LayoutActionServiceCEImpl
rg -U "public\s+Mono<ActionDTO>\s+createAction\([^)]+\)\s*\{[\s\S]+?(?=\n\s*\})" app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java

# Also check if LayoutActionServiceImpl overrides the method
rg -U "public\s+Mono<ActionDTO>\s+createAction\([^)]+\)\s*\{[\s\S]+?(?=\n\s*\})" app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java

Length of output: 1042


Script:

#!/bin/bash
# Look for the implementation of createAction in LayoutActionServiceCEImpl
rg "createAction.*\(" -A 20 app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java

# Check if LayoutActionServiceImpl has any createAction implementation
rg "createAction.*\(" -A 20 app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java

Length of output: 3040

app/server/appsmith-server/src/main/java/com/appsmith/server/fork/internal/ApplicationForkingServiceCEImpl.java (2)

Line range hint 1-624: Implementation follows reactive patterns effectively.

The forking implementation properly handles async operations, maintains transaction consistency, and has good error handling. The new parameter addition is well-integrated into the existing reactive chain.


317-318: 🛠️ Refactor suggestion

Verify the null parameter usage in createAction.

The new parameter is currently set to null, which aligns with the backward compatibility pattern but may not achieve the intended optimization of reducing redundant page DB calls.

Consider passing the already fetched page object instead of null to avoid redundant DB calls, as per the PR objective.

✅ Verification successful

Let me gather more information about the createAction method implementation.


Let me try a different search pattern to find the method definition.


Let me check the interface definition to understand the expected parameter type.


The null parameter for NewPage is correct in this context

The createAction method in LayoutActionServiceCE accepts NewPage as its fourth parameter, which is optional (can be null) based on the implementation pattern seen across the codebase. In the application forking flow, passing null is appropriate since we're not creating the action in the context of a new page.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other createAction calls that might need updating
ast-grep --pattern 'layoutActionService.createAction($_, $_, $_, $_)'

# Check the implementation of createAction
ast-grep --pattern 'createAction(ActionDTO $_, AppsmithEventContext $_, Boolean $_, $_)'

Length of output: 2107


Script:

#!/bin/bash
# Search for the createAction method definition in the LayoutActionService
ast-grep --pattern 'createAction(ActionDTO $_, AppsmithEventContext $_, Boolean $_, Page $_)'

# Search for any references to this method in interfaces or parent classes
rg "createAction.*Page\s+page\)" -A 5

Length of output: 135


Script:

#!/bin/bash
# Search for createAction method in LayoutActionService with broader pattern
rg "createAction.*ActionDTO.*Boolean" -A 10

# Also check for the interface definition
fd -e java LayoutActionService

Length of output: 2340


Script:

#!/bin/bash
# Check the interface definition for createAction
cat app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java

# Also check NewPage usage
rg "class NewPage" -A 5

Length of output: 8380

@@ -54,7 +54,7 @@ public Mono<Void> cloneEntities(ClonePageMetaDTO clonePageMetaDTO) {
// Indicates that source of action creation is clone page action
cloneActionDTO.setSource(ActionCreationSourceTypeEnum.CLONE_PAGE);
copyNestedNonNullProperties(actionDTO, cloneActionDTO);
return layoutActionService.createAction(cloneActionDTO, eventContext, isJsAction);
return layoutActionService.createAction(cloneActionDTO, eventContext, isJsAction, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

Pass clonePageMetaDTO.getClonedPageDTO() instead of null

The ClonePageMetaDTO contains the cloned page via getClonedPageDTO() and we can see it's already being used in the same method to set the page ID. Pass this page object to optimize the DB calls as intended.

-return layoutActionService.createAction(cloneActionDTO, eventContext, isJsAction, null);
+return layoutActionService.createAction(cloneActionDTO, eventContext, isJsAction, clonePageMetaDTO.getClonedPageDTO());
🔗 Analysis chain

Consider passing the actual page object instead of null

While the infrastructure change to accept the page parameter is in place, passing null here doesn't achieve the optimization goal of reducing redundant page fetches. The page object should be available from clonePageMetaDTO.getClonedPageDTO().

Let's verify if we can access the page object:

Consider this approach if the page object is available:

-return layoutActionService.createAction(cloneActionDTO, eventContext, isJsAction, null);
+return layoutActionService.createAction(cloneActionDTO, eventContext, isJsAction, clonePageMetaDTO.getClonedPageDTO());
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if ClonedPageDTO contains the complete page object
ast-grep --pattern 'class ClonePageMetaDTO {
  $$$
  getClonedPageDTO() {
    $$$
  }
  $$$
}'

Length of output: 96


Script:

#!/bin/bash
# Let's try a different approach to find the ClonePageMetaDTO class
rg -l "ClonePageMetaDTO" 

# Then check the ActionClonePageServiceCEImpl class to understand the context
rg -A 5 "createAction.*cloneActionDTO.*eventContext.*isJsAction" 

Length of output: 1553


Script:

#!/bin/bash
# Let's check the ClonePageMetaDTO class definition
rg -A 10 "class ClonePageMetaDTO" app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ClonePageMetaDTO.java

# And check how clonePageMetaDTO is used in the ActionClonePageServiceCEImpl
rg -B 5 -A 5 "clonePageMetaDTO" app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/clonepage/ActionClonePageServiceCEImpl.java

Length of output: 1715

Copy link

Deploy-Preview-URL: https://ce-37668.dp.appsmith.com

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.

@sneha122 can we please add a unit test to assert the removal of redundant page DB calls. Other changes look good to me.

? Mono.just(newPage)
: newPageService
.findById(action.getPageId(), aclPermission)
.name(GET_PAGE_BY_ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this anything more than the DB call? Can we rely on db metrics for this instead? This is if we intended to keep this longer than the duration of this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Product Issues related to a specific integration ok-to-test Required label for CI Query & JS Pod Issues related to the query & JS Pod skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Optimise page fetch time taking during Js object action creation
3 participants