chore: add feature flag for app computation cache (#40543)

## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

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

### 🔍 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/14789475280>
> Commit: 8c69931e4d5fb6b319883e8d1ba33f553029f346
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=14789475280&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Fri, 02 May 2025 07:00:53 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 feature flag to control the computation cache
capability.
- **Enhancements**
- Added checks to ensure computation caching only occurs when the
corresponding feature flag is enabled.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Diljit 2025-05-05 17:55:25 +05:30 committed by GitHub
parent b310d751e4
commit 4eae26879b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -58,6 +58,7 @@ export const FEATURE_FLAG = {
release_git_package_enabled: "release_git_package_enabled", release_git_package_enabled: "release_git_package_enabled",
license_external_saas_plugins_enabled: license_external_saas_plugins_enabled:
"license_external_saas_plugins_enabled", "license_external_saas_plugins_enabled",
release_computation_cache_enabled: "release_computation_cache_enabled",
} as const; } as const;
export type FeatureFlag = keyof typeof FEATURE_FLAG; export type FeatureFlag = keyof typeof FEATURE_FLAG;
@ -106,6 +107,7 @@ export const DEFAULT_FEATURE_FLAG_VALUE: FeatureFlags = {
release_table_custom_sort_function_enabled: false, release_table_custom_sort_function_enabled: false,
release_git_package_enabled: false, release_git_package_enabled: false,
license_external_saas_plugins_enabled: false, license_external_saas_plugins_enabled: false,
release_computation_cache_enabled: false,
}; };
export const AB_TESTING_EVENT_KEYS = { export const AB_TESTING_EVENT_KEYS = {

View File

@ -7,6 +7,8 @@ import { APP_MODE } from "entities/App";
import localforage from "localforage"; import localforage from "localforage";
import loglevel from "loglevel"; import loglevel from "loglevel";
import { AppComputationCache } from "./index"; import { AppComputationCache } from "./index";
import { WorkerEnv } from "workers/Evaluation/handlers/workerEnv";
import type { FeatureFlags } from "ee/entities/FeatureFlag";
jest.useFakeTimers(); jest.useFakeTimers();
@ -68,6 +70,9 @@ describe("AppComputationCache", () => {
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks(); jest.clearAllMocks();
AppComputationCache.resetInstance(); AppComputationCache.resetInstance();
WorkerEnv.setFeatureFlags({
release_computation_cache_enabled: true,
} as FeatureFlags);
// Now instantiate the singleton after mocks are set up // Now instantiate the singleton after mocks are set up
appComputationCache = AppComputationCache.getInstance(); appComputationCache = AppComputationCache.getInstance();

View File

@ -9,6 +9,7 @@ import {
} from "./types"; } from "./types";
import debounce from "lodash/debounce"; import debounce from "lodash/debounce";
import { isFinite, isNumber, isString } from "lodash"; import { isFinite, isNumber, isString } from "lodash";
import { WorkerEnv } from "workers/Evaluation/handlers/workerEnv";
interface ICachedData<T> { interface ICachedData<T> {
value: T; value: T;
@ -82,6 +83,12 @@ export class AppComputationCache {
5000, 5000,
); );
isComputationCacheFeatureEnabled() {
const featureFlags = WorkerEnv.getFeatureFlags();
return featureFlags["release_computation_cache_enabled"] || false;
}
/** /**
* Check if the computation result should be cached based on the app mode configuration * Check if the computation result should be cached based on the app mode configuration
* @returns - A boolean indicating whether the cache should be enabled for the given app mode * @returns - A boolean indicating whether the cache should be enabled for the given app mode
@ -95,7 +102,8 @@ export class AppComputationCache {
if ( if (
!this.isAppModeValid(appMode) || !this.isAppModeValid(appMode) ||
!this.isTimestampValid(timestamp) || !this.isTimestampValid(timestamp) ||
!this.isDSLVersionValid(dslVersion) !this.isDSLVersionValid(dslVersion) ||
!this.isComputationCacheFeatureEnabled()
) { ) {
return false; return false;
} }