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: Add indexes for policyMap to improve query response time #35676

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Aug 14, 2024

Description

Ref thread: https://theappsmith.slack.com/archives/C0341RERY4R/p1723548842255209?thread_ts=1723445955.346459&cid=C0341RERY4R

/test Workspace

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10380730889
Commit: 915e932
Cypress dashboard.
Tags: @tag.Workspace
Spec:


Wed, 14 Aug 2024 03:42:23 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced new constants to improve handling of deprecated field names and enhance multi-tenant functionalities, including DELETED_AT, TENANT_ID, and PERMISSION_GROUPS.
    • Implemented migration processes for updating tenant policies and optimizing query performance with new database indexes.
  • Bug Fixes

    • Improved system stability by refining the declaration of constants, ensuring immutability for POLICIES and enhancing error logging for database migrations.

Copy link
Contributor

coderabbitai bot commented Aug 14, 2024

Walkthrough

The recent changes enhance the structure and functionality of the application by introducing new constants for better field management, optimizing database interactions with index migrations, and refining policy handling for tenants. These updates improve code readability, efficiency, and support for multi-tenant functionality, ultimately contributing to a more robust application architecture.

Changes

File Path Summary
.../constants/DeprecatedFieldName.java, .../constants/FieldName.java Modified constants to public static final for immutability in DeprecatedFieldName. Added new constants in FieldName for enhanced field representation.
.../db/ce/Migration060AddIndexesForPolicyMap.java, .../db/ce/Migration061TenantPolicySetToPolicyMap.java Introduced migration classes to add indexes for performance and convert tenant policy sets into policy map formats, improving database efficiency and handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Application
    participant Database

    User->>Application: Request policy information
    Application->>Database: Query policies
    Database-->>Application: Return policy data
    Application-->>User: Send policy information

    Note over Application: Migration processes add indexes and update tenant policies in the background.
Loading

🎉 In the land of code, where changes unfold,
New constants arise, both brave and bold.
With indexes in place, our queries will soar,
Tenant policies mapped, efficiency at the core!
So let’s celebrate this upgrade we see,
A brighter future for our app, full of glee! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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 Aug 14, 2024
})
.subscribeOn(Schedulers.boundedElastic());

Mono.zip(readWorkspaceMono, manageWorkspaceMono).block();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is being referenced from performance advisor.

Screenshot 2024-08-14 at 8 10 01 AM

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, codebase verification and nitpick comments (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration060AddIndexesForPolicyMap.java (4)

4-6: Ensure Correct Use of Annotations.

The @ChangeUnit, @Execution, and @RollbackExecution annotations are used correctly for defining a migration unit. However, ensure that the author field is filled out appropriately as per project conventions.


34-34: Fill in the author field in @ChangeUnit.

The author field in the @ChangeUnit annotation is currently empty. It's important to fill this field with the appropriate author's name or identifier to maintain proper documentation and traceability.


38-39: Consider Implementing a Rollback Strategy.

Currently, the rollbackExecution method is empty. While the learnings indicate that not all migrations require a rollback, consider whether a rollback strategy is necessary for this migration to ensure data integrity in case of issues.


78-90: Handle Exceptions Appropriately.

The createAndApplyIndex method handles exceptions by logging errors. This is a good practice, but consider whether additional actions should be taken in case of failure, such as alerting or retry mechanisms, depending on the criticality of the index creation.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3bdd871 and 1bcea5f.

Files selected for processing (4)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/constants/DeprecatedFieldName.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/constants/FieldName.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration060AddIndexesForPolicyMap.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration061TenantPolicySetToPolicyMap.java (1 hunks)
Additional context used
Learnings (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration060AddIndexesForPolicyMap.java (2)
Learnt from: mohanarpit
PR: appsmithorg/appsmith#29676
File: app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration039AddCompoundIndexForDatasourceStorage.java:18-18
Timestamp: 2023-12-18T07:46:35.484Z
Learning: The team does not practice including the author's name in the `@ChangeUnit` annotation.
Learnt from: trishaanand
PR: appsmithorg/appsmith#30087
File: app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration043AddIndexActionCollectionPageID.java:27-28
Timestamp: 2024-01-08T07:11:52.229Z
Learning: The user has clarified that the migration `Migration043AddIndexActionCollectionPageID` is not critical and does not require a rollback strategy.
Additional comments not posted (6)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/constants/DeprecatedFieldName.java (2)

4-5: Good practice: Constants are now immutable.

Changing POLICIES to public static final enforces immutability, which is a good practice for constants. The addition of DELETED as a constant also enhances clarity in the codebase.


5-5: Verify usage of the new DELETED constant.

Ensure that the DELETED constant is used consistently across the codebase where applicable. This helps maintain clarity and consistency in handling deprecated fields.

Verification successful

The DELETED constant is used appropriately in the migration script.

The DELETED constant is being used in the Migration060AddIndexesForPolicyMap.java file to create a compound index with the deletedAt field. This is a valid and consistent use of the constant, ensuring efficient query operations involving these fields.

  • File: Migration060AddIndexesForPolicyMap.java
  • Usage: Creating a compound index with deletedAt to optimize database queries.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new `DELETED` constant across the codebase.

# Test: Search for the usage of `DELETED`. Expect: Consistent usage across relevant files.
rg --type java 'DeprecatedFieldName.DELETED'

Length of output: 246


Script:

#!/bin/bash
# Extract lines around the usage of `DELETED` in the Migration060AddIndexesForPolicyMap.java file for context.
rg --type java -A 10 -B 10 'DeprecatedFieldName.DELETED' app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration060AddIndexesForPolicyMap.java

Length of output: 1488

app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/constants/FieldName.java (2)

5-7: New constants improve clarity and support new functionalities.

The addition of DELETED_AT, TENANT_ID, and PERMISSION_GROUPS as constants enhances the codebase by providing clear, consistent references for these fields.


5-7: Verify usage of new constants.

Ensure that the new constants are used consistently across the codebase where applicable. This helps maintain clarity and consistency in handling these fields.

Verification successful

The new constants are used consistently across the codebase.

The constants DELETED_AT, TENANT_ID, and PERMISSION_GROUPS are utilized in various parts of the codebase, including repository implementations and migration scripts. This consistent usage helps maintain clarity and consistency in handling these fields.

  • Files where constants are used:
    • BaseAppsmithRepositoryCEImpl.java
    • BaseRepositoryImpl.java
    • Various migration files such as Migration017UnsetEncryptionVersion2Fields.java, Migration027AddIndexDatasourceIdAndDeletedInAction.java, and more.

This indicates that the new constants are integrated well into the existing code structure. If there are specific areas of concern, a targeted manual review might be necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new constants across the codebase.

# Test: Search for the usage of `DELETED_AT`, `TENANT_ID`, and `PERMISSION_GROUPS`. Expect: Consistent usage across relevant files.
rg --type java 'FieldName.DELETED_AT|FieldName.TENANT_ID|FieldName.PERMISSION_GROUPS'

Length of output: 4039

app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration061TenantPolicySetToPolicyMap.java (1)

21-57: Migration logic is clear and well-structured.

The migration effectively transitions policy sets to policy maps and includes cache eviction to maintain consistency. Ensure thorough testing of this migration in a safe environment before deployment.

app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration060AddIndexesForPolicyMap.java (1)

41-76: Parallel Execution of Index Creation.

The use of Mono.zip to execute the index creation in parallel is a good approach for non-blocking operations. Ensure that this does not lead to any race conditions or unexpected behavior in your specific use case.

@abhvsn
Copy link
Contributor Author

abhvsn commented Aug 14, 2024

Screenshot 2024-08-14 at 8 30 28 AM

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1bcea5f and 915e932.

Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration060AddIndexesForPolicyMap.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration060AddIndexesForPolicyMap.java

@abhvsn abhvsn added the ok-to-test Required label for CI label Aug 14, 2024
@abhvsn abhvsn enabled auto-merge (squash) August 14, 2024 03:46
@abhvsn abhvsn merged commit 8ad9b4a into release Aug 14, 2024
55 checks passed
@abhvsn abhvsn deleted the chore/add-indexes branch August 14, 2024 04:36
abhvsn added a commit that referenced this pull request Aug 14, 2024
## Description
Ref thread:
https://theappsmith.slack.com/archives/C0341RERY4R/p1723548842255209?thread_ts=1723445955.346459&cid=C0341RERY4R

/test Workspace

### 🔍 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/10380730889>
> Commit: 915e932
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10380730889&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Workspace`
> Spec:
> <hr>Wed, 14 Aug 2024 03:42:23 UTC
<!-- end of auto-generated comment: Cypress test results  -->

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

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

- **New Features**
- Introduced new constants to improve handling of deprecated field names
and enhance multi-tenant functionalities, including `DELETED_AT`,
`TENANT_ID`, and `PERMISSION_GROUPS`.
- Implemented migration processes for updating tenant policies and
optimizing query performance with new database indexes.

- **Bug Fixes**
- Improved system stability by refining the declaration of constants,
ensuring immutability for `POLICIES` and enhancing error logging for
database migrations.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

(cherry picked from commit 8ad9b4a)
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