Skip to content

chore: refactor crud methods#38158

Merged
AnaghHegde merged 5 commits intoreleasefrom
chore/new-action-crud-repo-refactor
Dec 19, 2024
Merged

chore: refactor crud methods#38158
AnaghHegde merged 5 commits intoreleasefrom
chore/new-action-crud-repo-refactor

Conversation

@AnaghHegde
Copy link
Contributor

@AnaghHegde AnaghHegde commented Dec 13, 2024

Description

As part of transaction support in PG, we are moving from using the jpa methods for database operations. This PR is refactoring the code to use custom repository class for DatasourceStorageRepository from the default CrudRepository.

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12406578294
Commit: c7efa63
Cypress dashboard.
Tags: @tag.ImportExport
Spec:


Thu, 19 Dec 2024 05:27:22 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced new methods for retrieving and counting NewAction entities based on application ID and IDs collection.
  • Bug Fixes

    • Removed outdated methods from the NewActionRepositoryCE interface to streamline functionality.
  • Refactor

    • Enhanced repository capabilities for managing NewAction entities while maintaining backward compatibility.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The changes in this pull request involve modifications to the CustomNewActionRepositoryCE interface and its implementation, along with the NewActionRepositoryCE interface. New methods for retrieving and counting NewAction entities have been added, while some existing methods have been removed from NewActionRepositoryCE. The new methods enhance the repository's capabilities without altering existing functionalities, ensuring backward compatibility where necessary.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java - Added: Flux<NewAction> findByApplicationId(String applicationId)
- Added: Flux<NewAction> findAllByIdIn(Iterable<String> ids)
- Added: Mono<Long> countByDeletedAtNull()
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java - Added: public Flux<NewAction> findByApplicationId(String applicationId)
- Added: public Flux<NewAction> findAllByIdIn(Iterable<String> ids)
- Added: public Mono<Long> countByDeletedAtNull()
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java - Removed: Flux<NewAction> findByApplicationId(String applicationId)
- Removed: Flux<NewAction> findAllByIdIn(Iterable<String> ids)
- Removed: Mono<Long> countByDeletedAtNull()

Possibly related PRs

  • chore: refactor new page crud repo methods #38169: The changes in this PR involve adding methods to the CustomNewPageRepositoryCE interface that are directly related to the new methods added in the main PR for counting and finding NewAction entities by application ID, indicating a similar enhancement in repository functionality.
  • chore: refactor crud to custom repository #38134: This PR refactors CRUD operations to a custom repository, which aligns with the main PR's focus on enhancing repository capabilities for NewAction entities, suggesting a broader initiative to improve data handling across repositories.
  • chore: refactor the crud method to custom repo class #38137: This PR introduces a new method for finding ActionCollection objects by application ID, which is conceptually similar to the new methods added in the main PR for NewAction, indicating a related effort to streamline data retrieval processes.

Suggested reviewers

  • abhvsn
  • sharat87

🎉 In the repository's realm, new methods take flight,
Counting actions and fetching with might.
Old paths are cleared, yet some still remain,
Enhancing our queries, like sunshine after rain.
With each line of code, new features unfold,
A dance of logic, a story retold! 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05237eb and c7efa63.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java (2 hunks)
🔇 Additional comments (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java (4)

32-32: LGTM: Import is appropriate

The StreamSupport import is correctly used for converting Iterable to List in the findAllByIdIn method.


493-498: LGTM: Method implementation is correct

The method provides a simplified version for querying by applicationId without permission checks, consistent with the repository's pattern.


500-504: LGTM: Implementation addresses previous review concerns

The method now correctly uses the 'id' field and safely converts Iterable to List using StreamSupport.


506-511: ⚠️ Potential issue

Fix inverted logic in deletedAt check

The method name countByDeletedAtNull suggests counting records where deletedAt is null, but the implementation counts records where deletedAt exists.

Apply this fix:

-public Mono<Long> countByDeletedAtNull() {
-    return queryBuilder()
-            .criteria(Bridge.exists(NewAction.Fields.deletedAt))
-            .count();
-}
+public Mono<Long> countByDeletedAtNull() {
+    return queryBuilder()
+            .criteria(Bridge.isNull(NewAction.Fields.deletedAt))
+            .count();
+}

Likely invalid or redundant comment.


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 the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Dec 13, 2024
@AnaghHegde AnaghHegde added the ok-to-test Required label for CI label Dec 13, 2024
@AnaghHegde AnaghHegde requested review from abhvsn and removed request for nidhi-nair and sondermanish December 13, 2024 10:31
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: 3

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

494-499: Consider consolidating duplicate methods

This method duplicates the existing findByApplicationId(String, AclPermission) with only the permission check removed. Consider using the existing method with an Optional permission parameter for better code maintainability.

-public Flux<NewAction> findByApplicationId(String applicationId) {
-    return queryBuilder()
-            .criteria(Bridge.equal(NewAction.Fields.applicationId, applicationId))
-            .all();
-}
+public Flux<NewAction> findByApplicationId(String applicationId) {
+    return findByApplicationId(applicationId, null);
+}
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java (1)

9-9: LGTM! Well-structured repository interface enhancements.

The new methods complement the existing functionality while adding optimized paths for bulk operations. The cursor batch size of 10000 is appropriate for MongoDB operations at this scale.

Consider documenting these performance-optimized methods in the interface to help other developers choose the most efficient method for their use case.

Also applies to: 85-91

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f88466 and ee9030b.

📒 Files selected for processing (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java (3 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java (0 hunks)
💤 Files with no reviewable changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java
🔇 Additional comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java (2)

91-91: LGTM! Clean and follows naming conventions.

The method name clearly describes its purpose and follows Spring Data naming conventions.


85-86: Verify security implications of permission-less query.

The new findByApplicationId overload doesn't include ACL permissions. Ensure this is intentionally designed for internal/system use only.

✅ Verification successful

Let me analyze the usage patterns and security context with these broader searches.


Permission-less query is used safely in internal system operations

The permission-less findByApplicationId(String) method is correctly implemented and used appropriately:

  • It's used internally by system services like ApplicationSnapshotService, PolicySolution, and import/export operations
  • Other public-facing methods use the secured overloads that require AclPermission
  • The implementation in CustomNewActionRepositoryCEImpl shows it's a basic query without any sensitive data exposure
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages to verify security context
rg -A 5 "findByApplicationId\(String\)" --type java

Length of output: 53


Script:

#!/bin/bash
# Search for usages with broader pattern to catch all variants
rg -A 5 "findByApplicationId" --type java

# Search for class definition to understand context
ast-grep --pattern 'interface $_ {
  $$$
  findByApplicationId($$$) {
    $$$
  }
  $$$
}'

# Look for similar methods with security checks
rg -A 5 "findByApplication.*Permission" --type java

Length of output: 65724

@Override
public Flux<NewAction> findAllByIdIn(Iterable<String> ids) {
return queryBuilder()
.criteria(Bridge.in(NewAction.Fields.applicationId, IteratorUtils.toList((Iterator) ids)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be NewAction.Fields.id?

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.

Comments added

@AnaghHegde AnaghHegde requested a review from abhvsn December 14, 2024 11:08
Flux<NewAction> findByApplicationId(String applicationId);

// @Meta(cursorBatchSize = 10000)
// TODO Implement cursor with batch size
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the .all() method to implement the batching, which will make sure all the DB calls by default will be batched.

abhvsn
abhvsn previously approved these changes Dec 16, 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 comment.

@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 18, 2024
@appsmithorg appsmithorg deleted a comment from github-actions bot Dec 18, 2024
@AnaghHegde AnaghHegde merged commit d9b1729 into release Dec 19, 2024
@AnaghHegde AnaghHegde deleted the chore/new-action-crud-repo-refactor branch December 19, 2024 09:54
NandanAnantharamu pushed a commit that referenced this pull request Dec 27, 2024
## Description
As part of transaction support in PG, we are moving from using the jpa
methods for database operations. This PR is refactoring the code to use
custom repository class for DatasourceStorageRepository from the default
CrudRepository.

## Automation

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

### 🔍 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/12406578294>
> Commit: c7efa63
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12406578294&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.ImportExport`
> Spec:
> <hr>Thu, 19 Dec 2024 05:27:22 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

## Summary by CodeRabbit

- **New Features**
- Introduced new methods for retrieving and counting `NewAction`
entities based on application ID and IDs collection.

- **Bug Fixes**
- Removed outdated methods from the `NewActionRepositoryCE` interface to
streamline functionality.

- **Refactor**
- Enhanced repository capabilities for managing `NewAction` entities
while maintaining backward compatibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
## Description
As part of transaction support in PG, we are moving from using the jpa
methods for database operations. This PR is refactoring the code to use
custom repository class for DatasourceStorageRepository from the default
CrudRepository.

## Automation

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

### 🔍 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/12406578294>
> Commit: c7efa63
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12406578294&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.ImportExport`
> Spec:
> <hr>Thu, 19 Dec 2024 05:27:22 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

## Summary by CodeRabbit

- **New Features**
- Introduced new methods for retrieving and counting `NewAction`
entities based on application ID and IDs collection.

- **Bug Fixes**
- Removed outdated methods from the `NewActionRepositoryCE` interface to
streamline functionality.

- **Refactor**
- Enhanced repository capabilities for managing `NewAction` entities
while maintaining backward compatibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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