Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(formula): get dirty data (#2837)

Univerb3ebd7970309
diff --git a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
index 9a90ad7358..bc3b44dbc9 100644
--- a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
+++ b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
@@ -14,30 +14,19 @@
* limitations under the License.
*/
-import type { IExecutionOptions, IMutation, IUnitRange, Nullable } from '@univerjs/core';
+import type { IExecutionOptions, IMutation, Nullable } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
import type {
- IDirtyUnitFeatureMap,
- IDirtyUnitOtherFormulaMap,
- IDirtyUnitSheetDefinedNameMap,
- IDirtyUnitSheetNameMap,
IRuntimeOtherUnitDataType,
IRuntimeUnitDataPrimitiveType,
} from '../../basics/common';
import type { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service';
-
-export interface IFormulaDirtyData {
- dirtyRanges: IUnitRange[];
- dirtyNameMap: IDirtyUnitSheetNameMap;
- dirtyDefinedNameMap: IDirtyUnitSheetDefinedNameMap;
- dirtyUnitFeatureMap: IDirtyUnitFeatureMap;
- dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;
-}
+import type { IFormulaDirtyData } from '../../services/current-data.service';
export interface ISetFormulaCalculationStartMutation extends IFormulaDirtyData {
options: Nullable<IExecutionOptions>;
- forceCalculation?: boolean;
+ forceCalculation: boolean;
}
/**
* TODO: @DR-Univer
diff --git a/packages/engine-formula/src/engine/dependency/dependency-tree.ts b/packages/engine-formula/src/engine/dependency/dependency-tree.ts
index 30dfc364f7..7744470c3a 100644
--- a/packages/engine-formula/src/engine/dependency/dependency-tree.ts
+++ b/packages/engine-formula/src/engine/dependency/dependency-tree.ts
@@ -24,6 +24,8 @@ import type {
IUnitExcludedCell,
} from '../../basics/common';
import type { BaseAstNode } from '../ast-node/base-ast-node';
+import type { IFormulaDirtyData } from '../../services/current-data.service';
+import type { IAllRuntimeData } from '../../services/runtime.service';
export enum FDtreeStateType {
DEFAULT,
@@ -68,7 +70,7 @@ export class FormulaDependencyTree extends Disposable {
featureId: Nullable<string>;
getDirtyData: Nullable<
- (tree: FormulaDependencyTree) => {
+ (dirtyData: IFormulaDirtyData, runtimeData: IAllRuntimeData) => {
runtimeCellData: IRuntimeUnitDataType;
dirtyRanges: IFeatureDirtyRangeType;
}
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts
index f6cb4f1efe..f4e4c07162 100644
--- a/packages/engine-formula/src/index.ts
+++ b/packages/engine-formula/src/index.ts
@@ -115,7 +115,7 @@ export { matchRefDrawToken } from './basics/match-token';
export { IDefinedNamesService, DefinedNamesService, type IDefinedNamesServiceParam, type IDefinedNameMapItem } from './services/defined-names.service';
export { isFormulaTransformable, transformFormula } from './engine/utils/relative-formula';
export { IFormulaRuntimeService, FormulaRuntimeService } from './services/runtime.service';
-export { IFormulaCurrentConfigService, FormulaCurrentConfigService } from './services/current-data.service';
+export { IFormulaCurrentConfigService, FormulaCurrentConfigService, type IFormulaDirtyData } from './services/current-data.service';
export { IActiveDirtyManagerService } from './services/active-dirty-manager.service';
@@ -140,7 +140,6 @@ export {
type ISetFormulaCalculationStartMutation,
type ISetFormulaCalculationNotificationMutation,
type ISetFormulaCalculationResultMutation,
- type IFormulaDirtyData,
} from './commands/mutations/set-formula-calculation.mutation';
export { SetFormulaDataMutation, type ISetFormulaDataMutationParams } from './commands/mutations/set-formula-data.mutation';
export { SetOtherFormulaMutation, RemoveOtherFormulaMutation, type ISetOtherFormulaMutationParams, type IRemoveOtherFormulaMutationParams } from './commands/mutations/set-other-formula.mutation';
diff --git a/packages/engine-formula/src/services/calculate-formula.service.ts b/packages/engine-formula/src/services/calculate-formula.service.ts
index b5ee3fed2d..274ec30cfe 100644
--- a/packages/engine-formula/src/services/calculate-formula.service.ts
+++ b/packages/engine-formula/src/services/calculate-formula.service.ts
@@ -286,7 +286,7 @@ export class CalculateFormulaService extends Disposable {
* and return the dirty area marked by the feature,
* so as to allow the formulas depending on the dirty area to continue the calculation.
*/
- const { runtimeCellData, dirtyRanges } = getDirtyData(tree);
+ const { runtimeCellData, dirtyRanges } = getDirtyData(this._currentConfigService.getDirtyData(), this._runtimeService.getAllRuntimeData());
this._runtimeService.setRuntimeFeatureCellData(tree.featureId, runtimeCellData);
diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.ts
index cb0795818d..5193a03e67 100644
--- a/packages/engine-formula/src/services/current-data.service.ts
+++ b/packages/engine-formula/src/services/current-data.service.ts
@@ -34,6 +34,15 @@ import type {
} from '../basics/common';
import { convertUnitDataToRuntime } from '../basics/runtime';
+export interface IFormulaDirtyData {
+ forceCalculation: boolean;
+ dirtyRanges: IUnitRange[];
+ dirtyNameMap: IDirtyUnitSheetNameMap;
+ dirtyDefinedNameMap: IDirtyUnitSheetDefinedNameMap;
+ dirtyUnitFeatureMap: IDirtyUnitFeatureMap;
+ dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;
+}
+
export interface IFormulaCurrentConfigService {
load(config: IFormulaDatasetConfig): void;
@@ -79,6 +88,8 @@ export interface IFormulaCurrentConfigService {
setExecuteUnitId(unitId: string): void;
setExecuteSubUnitId(subUnitId: string): void;
+
+ getDirtyData(): IFormulaDirtyData;
}
export class FormulaCurrentConfigService extends Disposable implements IFormulaCurrentConfigService {
@@ -238,6 +249,17 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
this._mergeNameMap(this._sheetNameMap, this._dirtyNameMap);
}
+ getDirtyData(): IFormulaDirtyData {
+ return {
+ forceCalculation: this._forceCalculate,
+ dirtyRanges: this._dirtyRanges,
+ dirtyNameMap: this._dirtyNameMap,
+ dirtyDefinedNameMap: this._dirtyDefinedNameMap,
+ dirtyUnitFeatureMap: this._dirtyUnitFeatureMap,
+ dirtyUnitOtherFormulaMap: this._dirtyUnitOtherFormulaMap,
+ };
+ }
+
loadDirtyRangesAndExcludedCell(dirtyRanges: IUnitRange[], excludedCell?: IUnitExcludedCell) {
this._dirtyRanges = dirtyRanges;
diff --git a/packages/engine-formula/src/services/feature-calculation-manager.service.ts b/packages/engine-formula/src/services/feature-calculation-manager.service.ts
index af52a6ed50..d04b81812f 100644
--- a/packages/engine-formula/src/services/feature-calculation-manager.service.ts
+++ b/packages/engine-formula/src/services/feature-calculation-manager.service.ts
@@ -18,13 +18,14 @@ import type { IUnitRange, Nullable } from '@univerjs/core';
import { createIdentifier, Disposable } from '@univerjs/core';
import type { IFeatureDirtyRangeType, IRuntimeUnitDataType } from '../basics/common';
-import type { FormulaDependencyTree } from '../engine/dependency/dependency-tree';
+import type { IAllRuntimeData } from './runtime.service';
+import type { IFormulaDirtyData } from './current-data.service';
export interface IFeatureCalculationManagerParam {
unitId: string;
subUnitId: string;
dependencyRanges: IUnitRange[];
- getDirtyData: (currentDependencyTree: FormulaDependencyTree) => {
+ getDirtyData: (dirtyData: IFormulaDirtyData, runtimeData: IAllRuntimeData) => {
runtimeCellData: IRuntimeUnitDataType;
dirtyRanges: IFeatureDirtyRangeType;
};
diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
index 9e3eefe11d..36113cf695 100644
--- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
+++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
@@ -48,6 +48,7 @@ export class TriggerCalculationController extends Disposable {
private _waitingCommandQueue: ICommandInfo[] = [];
private _executingDirtyData: IFormulaDirtyData = {
+ forceCalculation: false,
dirtyRanges: [],
dirtyNameMap: {},
dirtyDefinedNameMap: {},
@@ -201,6 +202,7 @@ export class TriggerCalculationController extends Disposable {
dirtyDefinedNameMap: allDirtyDefinedNameMap,
dirtyUnitFeatureMap: allDirtyUnitFeatureMap,
dirtyUnitOtherFormulaMap: allDirtyUnitOtherFormulaMap,
+ forceCalculation: false,
// numfmtItemMap,
};
}
@@ -223,6 +225,7 @@ export class TriggerCalculationController extends Disposable {
dirtyDefinedNameMap: allDirtyDefinedNameMap,
dirtyUnitFeatureMap: allDirtyUnitFeatureMap,
dirtyUnitOtherFormulaMap: allDirtyUnitOtherFormulaMap,
+ forceCalculation: false,
};
}
@@ -432,6 +435,7 @@ export class TriggerCalculationController extends Disposable {
dirtyDefinedNameMap: {},
dirtyUnitFeatureMap: {},
dirtyUnitOtherFormulaMap: {},
+ forceCalculation: false,
};
}