appsmith
appsmith copied to clipboard
feat: Moved Tenant Information to Redis for quick access
Description
The tenant is fetched multiple times across the appsmith codebase but is rarely updated (from the admin settings). Every time a fetch call to the database is costly both in terms of resources and time taken. The consolidated api also makes a call to fetch the tenant and return to the client. To improve the performance of fetching the tenant information, we are moving the tenant information to redis cache for quicker fetch. This will improve the performance of the consolidated api and also reduce the time taken by all the different functionalities within the backend codebase which depend on tenant to process further.
TL;DR
Adds tenant information tenantService.getDefaultTenant()
to redis.
Fixes #33083
Automation
/ok-to-test tags=""
:mag: Cypress test results
[!CAUTION]
If you modify the content in this section, you are likely to disrupt the CI result for your PR.
Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
Failed server tests
- com.appsmith.server.services.ce.TenantServiceCETest#setEmailVerificationEnabled_WithValidSMTPHost_Success
- com.appsmith.server.services.ce.TenantServiceCETest#setMapsKeyAndGetItBack
- com.appsmith.server.services.ce.TenantServiceCETest#updateTenantConfiguration_updateStrongPasswordPolicy_success
Failed server tests
- com.external.plugins.RestApiPluginTest#testHttpGetRequestRawBody
Failed server tests
- com.appsmith.server.services.ce.TenantServiceCETest#setEmailVerificationEnabled_WithValidSMTPHost_Success
- com.appsmith.server.services.ce.TenantServiceCETest#updateTenantConfiguration_updateStrongPasswordPolicy_success
- com.appsmith.server.solutions.ApplicationForkingServiceTests#cloneApplicationForkWithConfigurationFalseWithActionsThrice
Failed server tests
- com.appsmith.server.services.ce.ApplicationServiceCETest#testUploadNavigationLogo_invalidImageSize
- com.appsmith.server.services.ce.TenantServiceCETest#setEmailVerificationEnabled_WithValidSMTPHost_Success
- com.appsmith.server.services.ce.TenantServiceCETest#updateTenantConfiguration_updateStrongPasswordPolicy_success
Failed server tests
- com.appsmith.server.services.ce.TenantServiceCETest#setEmailVerificationEnabled_WithValidSMTPHost_Success
- com.appsmith.server.services.ce.TenantServiceCETest#updateTenantConfiguration_updateStrongPasswordPolicy_success
Test updateTenantConfiguration_updateStrongPasswordPolicy_success
is failing weirdly with 2 different tenantIds getting populated in redis for a single test case. This is creating inconsistency and leading to failure of this test 😞
@NilanshBansal
Would it be possible to cache tenant configuration as part of this request
This DB call is made the first time tenant id is needed. It fetches the tenant configuration but only persists id in redis cache. The code can be changed to persist the whole configuration. Thoughts ?
@NilanshBansal
Would it be possible to cache tenant configuration as part of this request
This DB call is made the first time tenant id is needed. It fetches the tenant configuration but only persists id in redis cache. The code can be changed to persist the whole configuration. Thoughts ?
@rajatagrawal It is already the fastest call that we are making even faster than redis. Since this is being fetched from the class instance variable and not from any network call. Saying that, there are a lot of code level/readability improvements that we can make to this piece of code but purely from a performance standpoint it will not give us any perf boost.
[!WARNING]
Rate Limit Exceeded
@NilanshBansal has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 32 seconds before requesting another review.
How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the
@coderabbitai review
command as a PR comment. Alternatively, push new commits to this PR.We recommend that you space out your commits to avoid hitting the rate limit.
How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information.
Commits
Files that changed from the base of the PR and between bb21eaebb75e0b7dc24ecfcbddc9f609eef50ce9 and 306e77f1460caf5302e1dd39fc58cce35790a04b.
Walkthrough
The primary change involves implementing Redis caching for tenant configurations to reduce the latency of the tenants/current
API. This includes adding a CacheableRepositoryHelper
to the TenantServiceCEImpl
class for cache management and modifying methods to include cache eviction logic. Additionally, the findBySlug
method in TenantRepositoryCE
is marked as deprecated. Corresponding tests have been updated to reflect these changes.
Changes
Files | Change Summary |
---|---|
TenantServiceCEImpl.java |
Added CacheableRepositoryHelper for cache management; updated methods to include cache eviction logic. |
TenantRepositoryCE.java |
Deprecated findBySlug method with a comment to use tenantService.getDefaultTenant() instead. |
TenantServiceCETest.java |
Updated cleanup method to reset tenant configuration and handle errors. |
Assessment against linked issues
Objective | Addressed | Explanation |
---|---|---|
Implement caching for fetching tenant configuration (#33083) | ✅ | |
Invalidate cache if tenant configuration gets updated, update the database and rebuild cache (#33083) | ✅ |
The changes effectively implement Redis caching for tenant configurations and ensure cache invalidation and updates when tenant configurations are modified. This addresses the primary objectives of reducing latency for the tenants/current
API as outlined in the linked issue.
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?
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.
-
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 a review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai resolve
resolve all the CodeRabbit review comments. -
@coderabbitai help
to get help.
Additionally, you can add @coderabbitai ignore
anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration 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.
Failed server tests
- com.appsmith.server.services.ce.ApplicationServiceCETest#testUploadNavigationLogo_invalidImageSize
- com.appsmith.server.solutions.ApplicationForkingServiceTests#cloneApplicationForkWithConfigurationFalseWithActionsThrice