-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
base: release
Are you sure you want to change the base?
chore: removed redundant page DB calls from js action creation flow #37668
Conversation
WalkthroughThe changes in this pull request primarily involve modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
/build-deploy-preview skip-tests=true |
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12003842608. |
There was a problem hiding this 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
📒 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:
- Find actual implementations of the createAction method with the new parameter
- 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); |
There was a problem hiding this comment.
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
Deploy-Preview-URL: https://ce-37668.dp.appsmith.com |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
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?
Summary by CodeRabbit
New Features
Bug Fixes
executeOnLoad
property during action creation in cloning contexts.Tests