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 the crud method to custom repo class #38138

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

AnaghHegde
Copy link
Member

@AnaghHegde AnaghHegde commented Dec 12, 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 DatasourceRepository from the default CrudRepository.

Automation

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

🔍 Cypress test results

Tip

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


Wed, 18 Dec 2024 08:59:01 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced methods to retrieve Datasource objects by IDs and count non-deleted Datasource instances.
  • Bug Fixes
    • Removed outdated method signatures from the DatasourceRepositoryCE interface to streamline functionality.
  • Documentation
    • Added @Repository annotation to the DatasourceRepositoryCE interface for clarity on its role within the application.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes introduce new methods to the CustomDatasourceRepositoryCE and its implementation, CustomDatasourceRepositoryCEImpl, enhancing the functionality for managing Datasource entities. New methods allow for retrieving Datasource objects by a list of IDs and counting non-deleted instances. Additionally, the DatasourceRepositoryCE interface is updated with a new @Repository annotation and has some methods removed to simplify its structure.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCE.java Added methods: findByIdIn(List<String> ids), countByDeletedAtNull().
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCEImpl.java Added methods: findByIdIn(List<String> ids), countByDeletedAtNull().
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceRepositoryCE.java Added @Repository annotation; removed methods: findByIdIn, findAllByWorkspaceId, countByDeletedAtNull.

Possibly related PRs

Suggested reviewers

  • abhvsn
  • sharat87

🎉 In the realm of code, new methods arise,
With queries and counts, they reach for the skies.
A repository's dance, with permissions in tow,
Simplifying structures, making data flow!
So here's to the changes, both bold and bright,
In the world of Java, everything feels right! 🌟


📜 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 ac0e8ed and df7dc42.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCEImpl.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCE.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCEImpl.java

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@AnaghHegde AnaghHegde added the ok-to-test Required label for CI label Dec 12, 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 Dec 12, 2024
@AnaghHegde AnaghHegde requested review from abhvsn and removed request for nidhi-nair and sondermanish December 12, 2024 20:49
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/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCEImpl.java (1)

47-51: Consider adding batch size limit for large ID lists.

While the implementation is correct, consider adding a limit check for the size of the ID list to prevent potential performance issues with very large lists.

 @Override
 public Flux<Datasource> findByIdIn(List<String> ids) {
+    if (ids.size() > 1000) {
+        log.warn("Large batch size in findByIdIn: {}", ids.size());
+    }
     final BridgeQuery<Datasource> q = Bridge.in(Datasource.Fields.id, ids);
     return queryBuilder().criteria(q).all();
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ea5021 and ac0e8ed.

📒 Files selected for processing (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceRepositoryCE.java (1 hunks)
🔇 Additional comments (5)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceRepositoryCE.java (1)

7-7: LGTM! Clean interface design with proper separation of concerns.

The interface is now more focused with the policy-related method, while other CRUD operations are moved to the custom repository interface.

Also applies to: 12-14

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCE.java (2)

17-19: LGTM! Clear method signature for workspace-specific queries.

The method properly handles permission checks through the AclPermission parameter.


21-23: LGTM! Batch retrieval method properly defined.

The method signature for batch retrieval by IDs is clear and follows repository pattern best practices.

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceRepositoryCEImpl.java (2)

35-39: LGTM! Clean implementation using Bridge pattern.

The query construction is clear and follows the established pattern.


53-57: LGTM! Efficient query for counting active datasources.

The implementation correctly uses isNull check for counting non-deleted datasources.

@appsmithorg appsmithorg deleted a comment from github-actions bot Dec 13, 2024
@@ -28,4 +31,28 @@ public Mono<Datasource> findByNameAndWorkspaceId(String name, String workspaceId
.permission(aclPermission)
.one();
}

@Override
public Flux<Datasource> findByWorkspaceId(String workspaceId, AclPermission aclPermission) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not present in DatasourceRepoisitoryCE, are we adding this as a new methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a duplicate since the method already exists in custom implementation.

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.

Minor comments

@AnaghHegde AnaghHegde requested a review from abhvsn December 13, 2024 10:11
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.

Comment added!


Flux<Datasource> findByIdIn(List<String> ids);

Mono<Long> countByDeletedAtNull();
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 not adding Flux<Datasource> findAllByWorkspaceId(String workspaceId); or this is not used in CE and EE?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was not used anywhere in the code base. Hence removing this.

@AnaghHegde AnaghHegde requested a review from abhvsn December 18, 2024 08:17
@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 18, 2024
@AnaghHegde AnaghHegde merged commit 7d87c55 into release Dec 19, 2024
72 of 74 checks passed
@AnaghHegde AnaghHegde deleted the chore/refactor-datasource-crud-repository branch December 19, 2024 05:21
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 DatasourceRepository from the default
CrudRepository.

## Automation

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

### 🔍 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/12388978242>
> Commit: df7dc42
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12388978242&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource`
> Spec:
> <hr>Wed, 18 Dec 2024 08:59:01 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

- **New Features**
- Introduced methods to retrieve `Datasource` objects by IDs and count
non-deleted `Datasource` instances.
- **Bug Fixes**
- Removed outdated method signatures from the `DatasourceRepositoryCE`
interface to streamline functionality.
- **Documentation**
- Added `@Repository` annotation to the `DatasourceRepositoryCE`
interface for clarity on its role within the application.

<!-- 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 DatasourceRepository from the default
CrudRepository.

## Automation

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

### 🔍 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/12388978242>
> Commit: df7dc42
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12388978242&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource`
> Spec:
> <hr>Wed, 18 Dec 2024 08:59:01 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

- **New Features**
- Introduced methods to retrieve `Datasource` objects by IDs and count
non-deleted `Datasource` instances.
- **Bug Fixes**
- Removed outdated method signatures from the `DatasourceRepositoryCE`
interface to streamline functionality.
- **Documentation**
- Added `@Repository` annotation to the `DatasourceRepositoryCE`
interface for clarity on its role within the application.

<!-- 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