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 crud to custom repository #38134

Merged
merged 2 commits into from
Dec 12, 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 ApplicationRepository 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/12298562052
Commit: 72d6d37
Cypress dashboard.
Tags: @tag.ImportExport
Spec:


Thu, 12 Dec 2024 15:00:11 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced new methods for retrieving applications by ID, workspace ID, and cloned application ID.
    • Added functionality to count applications by workspace ID and deletion status.
    • Enhanced export options for applications.
  • Bug Fixes

    • Simplified access to applications by removing permission requirements in certain methods.

@AnaghHegde AnaghHegde self-assigned this Dec 12, 2024
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes in this pull request involve significant modifications to the ApplicationRepositoryCE interface and its related components. Several method definitions have been removed from ApplicationRepositoryCE and relocated to CustomApplicationRepositoryCE, which now includes new methods for querying applications. This restructuring enhances the repository's capabilities while simplifying access to application data.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ApplicationRepositoryCE.java - Removed multiple methods: findByIdIn, findByWorkspaceId, countByWorkspaceId, findByClonedFromApplicationId, countByDeletedAtNull, findByIdAndExportWithConfiguration.
- Added method: findIdsByWorkspaceId.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCE.java - Added methods: findByIdIn, findByWorkspaceId, countByWorkspaceId, findByClonedFromApplicationId, countByDeletedAtNull, findByIdAndExportWithConfiguration.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java - Added methods: findByIdIn, findByWorkspaceId, countByWorkspaceId, findByClonedFromApplicationId, countByDeletedAtNull, findByIdAndExportWithConfiguration.
- Updated existing methods to remove permission parameters.

Possibly related PRs

Suggested labels

skip-changelog, ok-to-test

Suggested reviewers

  • abhvsn
  • nidhi-nair
  • sharat87

🎉 In the realm of code, changes unfold,
Methods moved and new ones bold.
Applications now find their way,
Through custom paths, they brightly play.
A repository's dance, a developer's delight,
Enhancing our code, making it right! 🎊


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 requested a review from abhvsn December 12, 2024 14:32
@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 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 12, 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/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java (3)

302-306: Consider batch processing for findByIdIn method.

For better performance with large ID lists, consider implementing batch processing.

 public Flux<Application> findByIdIn(List<String> ids) {
+    // Process in batches of 100
+    return Flux.fromIterable(ids)
+            .buffer(100)
+            .flatMap(batch -> {
+                final BridgeQuery<Application> q = Bridge.in(Application.Fields.id, batch);
+                return queryBuilder().criteria(q).all();
+            });
 }

333-338: Consider adding an index for exportWithConfiguration queries.

The findByIdAndExportWithConfiguration method would benefit from an index on (id, exportWithConfiguration).


327-331: Review performance impact of countByDeletedAtNull.

For large datasets, counting all non-deleted applications might be expensive. Consider:

  1. Caching the count
  2. Using a counter collection
  3. Maintaining a running count
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e30a38 and 72d6d37.

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

12-12: LGTM! Clean interface refactoring.

The interface is now more focused with a single method returning IdOnly projection, which is more efficient for workspace-related queries.

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCE.java (1)

84-95: Verify transaction support for the new repository methods.

As this PR aims to enhance transaction support in PostgreSQL, we should verify that these methods work correctly within transactions.

✅ Verification successful

Let me gather more information about the transaction configuration and repository setup.


Let me check the repository configuration and transaction support more specifically.


Let me try a different approach to verify the repository configuration and transaction support.


Transaction support is properly configured for the repository methods

The repository is built on Spring's reactive MongoDB infrastructure with proper transaction support:

  • Extends BaseRepository which inherits from ReactiveMongoRepository
  • ReactiveMongoTransactionManager is configured in MongoConfig
  • Repository implementation uses Spring's reactive transaction management

The new repository methods will automatically participate in transactions when called from transactional service methods.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for transaction-related annotations or configurations
rg -l "@Transactional|TransactionConfiguration" --type java

# Look for transaction manager configurations
rg "TransactionManager|transaction-manager" --type xml --type java

Length of output: 1110


Script:

#!/bin/bash
# Check repository configuration and inheritance
ast-grep --pattern 'interface CustomApplicationRepositoryCE extends $$$'

# Check if the repository is reactive
ast-grep --pattern 'interface $_ extends ReactiveCrudRepository<$$$>'

# Look for transaction configuration in application properties
rg "spring.data.(mongodb|postgresql).transactionEnabled" --type properties --type yml

# Check for reactive repository configuration
rg "EnableReactiveMongoRepositories|EnableR2dbcRepositories" --type java

Length of output: 73399


Script:

#!/bin/bash
# Check repository configuration and inheritance
ast-grep --pattern 'interface CustomApplicationRepositoryCE extends $_'

# Check if the repository implementation has transaction annotations
rg "@Transactional" --type java -A 2 -B 2 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/

# Look for repository implementation class
rg "class.*implements.*CustomApplicationRepositoryCE" --type java

Length of output: 258


Script:

#!/bin/bash
# Search for repository class and interface with more context
rg -l "CustomApplicationRepositoryCE" --type java

# Look for reactive repository configuration
rg "ReactiveMongoRepository|ReactiveCrudRepository" --type java -A 2 -B 2

# Check for transaction configuration in MongoDB config
rg "ReactiveMongoTransactionManager|@EnableTransactionManagement" --type java -A 2 -B 2

Length of output: 13380

@AnaghHegde AnaghHegde merged commit 4ea5021 into release Dec 12, 2024
54 of 55 checks passed
@AnaghHegde AnaghHegde deleted the chore/refactor-crud-to-custom-repository branch December 12, 2024 19:22
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 `ApplicationRepository` 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/12298562052>
> Commit: 72d6d37
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12298562052&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.ImportExport`
> Spec:
> <hr>Thu, 12 Dec 2024 15:00:11 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 new methods for retrieving applications by ID, workspace
ID, and cloned application ID.
- Added functionality to count applications by workspace ID and deletion
status.
	- Enhanced export options for applications.
  
- **Bug Fixes**
- Simplified access to applications by removing permission requirements
in certain methods.

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