-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added LRU cache for mockDB connections (#36480)
## Description This PR implements an LRU (Least Recently Used) caching mechanism for the Mongo mockDB connections which get auto-cleaned up every 2 hours based on their access time. This is done to stop the overpopulation of the open dangling connections to the mockDB resulting in the max connection limit. The Caching Implementation used is [Google Guave Cache](https://github.com/google/guava/wiki/CachesExplained). Also refer - [Working of Guava cache ](https://medium.com/@alxkm/introduction-to-caching-with-google-guava-a-simple-and-flexible-solution-2c721427e72e) <img width="811" alt="image" src="https://github.com/user-attachments/assets/5abb3e05-13ea-421e-aaf0-22ac441f68e6"> Fixes #36474 ## Automation /ok-to-test tags="@tag.Sanity" ### 🔍 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/11066462645> > Commit: 38fcf57 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11066462645&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Fri, 27 Sep 2024 08:01:28 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 a new constant for the MongoDB plugin to enhance plugin identification. - Added a `DatasourcePluginContext` class to encapsulate datasource plugin context, including connection details and creation time. - Implemented a caching mechanism for datasource contexts to optimize connection management and reduce excessive database connections. - Added functionality to identify mock MongoDB datasources. - **Bug Fixes** - Enhanced cleanup processes for stale connections in the caching system. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
1 parent
6368215
commit e6cd973
Showing
3 changed files
with
132 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...er/appsmith-server/src/main/java/com/appsmith/server/domains/DatasourcePluginContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.appsmith.server.domains; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.time.Instant; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
public class DatasourcePluginContext<T> { | ||
private T connection; | ||
private String pluginId; | ||
private Instant creationTime; | ||
|
||
public DatasourcePluginContext() { | ||
creationTime = Instant.now(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters