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): sheet name dirty and async update (#649)

Univer0cb8c062867b
diff --git a/packages/engine-formula/src/dependency/dependency-tree.ts b/packages/engine-formula/src/dependency/dependency-tree.ts
index 4f1bbbff1a..07fc958377 100644
--- a/packages/engine-formula/src/dependency/dependency-tree.ts
+++ b/packages/engine-formula/src/dependency/dependency-tree.ts
@@ -2,7 +2,7 @@ import type { IRange, IUnitRange, Nullable } from '@univerjs/core';
import { Disposable } from '@univerjs/core';
import type { BaseAstNode } from '../ast-node/base-ast-node';
-import type { IUnitExcludedCell } from '../basics/common';
+import type { IDirtyUnitSheetNameMap, IUnitExcludedCell } from '../basics/common';
export enum FDtreeStateType {
DEFAULT,
@@ -60,7 +60,7 @@ export class FormulaDependencyTree extends Disposable {
return this._state === FDtreeStateType.SKIP;
}
- compareRangeData(range: IRange) {
+ inRangeData(range: IRange) {
const startRow = range.startRow;
const startColumn = range.startColumn;
const endRow = range.endRow;
@@ -81,6 +81,7 @@ export class FormulaDependencyTree extends Disposable {
*/
dependencyRange(
dependencyRangeList: Map<string, Map<string, IRange[]>>,
+ dirtyUnitSheetNameMap: IDirtyUnitSheetNameMap,
unitExcludedCell: Nullable<IUnitExcludedCell>
) {
if (this.rangeList.length === 0) {
@@ -89,9 +90,7 @@ export class FormulaDependencyTree extends Disposable {
for (let r = 0, len = this.rangeList.length; r < len; r++) {
const unitRange = this.rangeList[r];
- const unitId = unitRange.unitId;
- const sheetId = unitRange.sheetId;
- const range = unitRange.range;
+ const { unitId, sheetId, range } = unitRange;
if (!dependencyRangeList.has(unitId)) {
continue;
@@ -140,6 +139,14 @@ export class FormulaDependencyTree extends Disposable {
}
}
}
+
+ /**
+ * When a worksheet is inserted or deleted,
+ * the formulas that depend on these worksheets need to be calculated.
+ */
+ if (dirtyUnitSheetNameMap[unitId]?.[sheetId] != null) {
+ return true;
+ }
}
return false;
@@ -177,7 +184,7 @@ export class FormulaDependencyTree extends Disposable {
if (
dependenceTree.unitId === unitId &&
dependenceTree.subComponentId === sheetId &&
- dependenceTree.compareRangeData(range)
+ dependenceTree.inRangeData(range)
) {
return true;
}
diff --git a/packages/engine-formula/src/dependency/formula-dependency.ts b/packages/engine-formula/src/dependency/formula-dependency.ts
index d560ae7083..03da2401b2 100644
--- a/packages/engine-formula/src/dependency/formula-dependency.ts
+++ b/packages/engine-formula/src/dependency/formula-dependency.ts
@@ -10,7 +10,7 @@ import type { BaseAstNode } from '../ast-node/base-ast-node';
import { ErrorNode } from '../ast-node/base-ast-node';
import { NodeType } from '../ast-node/node-type';
import { FormulaAstLRU } from '../basics/cache-lru';
-import type { IFormulaData, IOtherFormulaData } from '../basics/common';
+import type { IDirtyUnitSheetNameMap, IFormulaData, IOtherFormulaData } from '../basics/common';
import { ErrorType } from '../basics/error-type';
import type { PreCalculateNodeType } from '../basics/node-type';
import { prefixToken, suffixToken } from '../basics/token';
@@ -28,6 +28,8 @@ export const FormulaASTCache = new FormulaAstLRU<AstRootNode>(FORMULA_CACHE_LRU_
export class FormulaDependencyGenerator extends Disposable {
private _updateRangeFlattenCache = new Map<string, Map<string, IRange[]>>();
+ private _dirtyUnitSheetNameMap: IDirtyUnitSheetNameMap = {};
+
constructor(
@IFormulaCurrentConfigService private readonly _currentConfigService: IFormulaCurrentConfigService,
@IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService,
@@ -41,6 +43,7 @@ export class FormulaDependencyGenerator extends Disposable {
override dispose(): void {
this._updateRangeFlattenCache.clear();
FormulaASTCache.clear();
+ this._dirtyUnitSheetNameMap = {};
}
async generate() {
@@ -216,6 +219,8 @@ export class FormulaDependencyGenerator extends Disposable {
this._addFlattenCache(unitId, sheetId, range);
}
+
+ this._dirtyUnitSheetNameMap = this._currentConfigService.getDirtyNameMap();
}
private _generateAstNode(formulaString: string, refOffsetX: number = 0, refOffsetY: number = 0) {
@@ -407,6 +412,7 @@ export class FormulaDependencyGenerator extends Disposable {
(forceCalculate ||
tree.dependencyRange(
this._updateRangeFlattenCache,
+ this._dirtyUnitSheetNameMap,
this._currentConfigService.getExcludedRange()
) ||
this._includeTree(tree)) &&
@@ -448,6 +454,14 @@ export class FormulaDependencyGenerator extends Disposable {
return false;
}
+ /**
+ * When the name of a worksheet is changed, or a worksheet is inserted or deleted,
+ * the formulas within it may not need to be calculated.
+ */
+ // if (this._dirtyUnitSheetNameMap[unitId][subComponentId] != null) {
+ // return true;
+ // }
+
if (!this._updateRangeFlattenCache.has(unitId)) {
return false;
}
@@ -461,7 +475,7 @@ export class FormulaDependencyGenerator extends Disposable {
const ranges = sheetRangeMap.get(subComponentId)!;
for (const range of ranges) {
- if (tree.compareRangeData(range)) {
+ if (tree.inRangeData(range)) {
return true;
}
}
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts
index 5878865e25..1101a16137 100644
--- a/packages/engine-formula/src/index.ts
+++ b/packages/engine-formula/src/index.ts
@@ -25,6 +25,7 @@ export { BaseReferenceObject, type FunctionVariantType } from './reference-objec
export { RangeReferenceObject } from './reference-object/range-reference-object';
export { FormulaEngineService } from './services/formula-engine.service';
export { IFunctionService } from './services/function.service';
+export { FormulaExecuteStageType, type IExecutionInProgressParams } from './services/runtime.service';
export { FormulaExecutedStateType, type IAllRuntimeData } from './services/runtime.service';
export { ArrayValueObject } from './value-object/array-value-object';
export { BaseValueObject } from './value-object/base-value-object';
diff --git a/packages/engine-formula/src/reference-object/base-reference-object.ts b/packages/engine-formula/src/reference-object/base-reference-object.ts
index a0b16653f6..bf8727320a 100644
--- a/packages/engine-formula/src/reference-object/base-reference-object.ts
+++ b/packages/engine-formula/src/reference-object/base-reference-object.ts
@@ -106,6 +106,10 @@ export class BaseReferenceObject extends ObjectClassType {
iterator(callback: (valueObject: CalculateValueType, rowIndex: number, columnIndex: number) => Nullable<boolean>) {
const { startRow, endRow, startColumn, endColumn } = this.getRangePosition();
+ if (this._checkIfComponentMiss()) {
+ return callback(new ErrorValueObject(ErrorType.VALUE), startRow, startColumn);
+ }
+
for (let r = startRow; r <= endRow; r++) {
for (let c = startColumn; c <= endColumn; c++) {
const cell = this.getCellData(r + this._refOffsetY, c + this._refOffsetX);
@@ -375,6 +379,13 @@ export class BaseReferenceObject extends ObjectClassType {
unitId: this.getUnitId(),
};
}
+
+ private _checkIfComponentMiss() {
+ if ((this._forcedSheetId == null || this._forcedSheetId.length === 0) && this._forcedSheetName.length > 0) {
+ return true;
+ }
+ return false;
+ }
}
export class AsyncObject extends ObjectClassType {
diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.ts
index cc9046a9d1..a2ba289a2c 100644
--- a/packages/engine-formula/src/services/current-data.service.ts
+++ b/packages/engine-formula/src/services/current-data.service.ts
@@ -30,6 +30,8 @@ export interface IFormulaCurrentConfigService {
getDirtyRanges(): IUnitRange[];
+ getDirtyNameMap(): IDirtyUnitSheetNameMap;
+
registerUnitData(unitData: IUnitData): void;
registerFormulaData(formulaData: IFormulaData): void;
@@ -105,6 +107,10 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
return this._dirtyRanges;
}
+ getDirtyNameMap() {
+ return this._dirtyNameMap;
+ }
+
load(config: IFormulaDatasetConfig) {
const { allUnitData, unitSheetNameMap } = this._loadSheetData();
diff --git a/packages/engine-formula/src/services/formula-engine.service.ts b/packages/engine-formula/src/services/formula-engine.service.ts
index 1918c68db6..34f5e99f2b 100644
--- a/packages/engine-formula/src/services/formula-engine.service.ts
+++ b/packages/engine-formula/src/services/formula-engine.service.ts
@@ -192,6 +192,13 @@ export class FormulaEngineService extends Disposable {
return this.lexerTreeBuilder.moveFormulaRefOffset(formulaString, refOffsetX, refOffsetY);
}
+ /**
+ * Stop the execution of the formula.
+ */
+ stopFormulaExecution() {
+ this.runtimeService.stopExecution();
+ }
+
/**
*
* @param unitId
diff --git a/packages/formula/package.json b/packages/formula/package.json
index 7a2a3ad3bf..b20d26e127 100644
--- a/packages/formula/package.json
+++ b/packages/formula/package.json
@@ -44,7 +44,8 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/core": "workspace:*",
- "@wendellhu/redi": "^0.12.11"
+ "@wendellhu/redi": "^0.12.11",
+ "rxjs": "^7.8.1"
},
"devDependencies": {
"@vitest/coverage-istanbul": "^0.34.6",
diff --git a/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts b/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
index 5938de01d8..d4aa4d9407 100644
--- a/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
+++ b/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
@@ -1,11 +1,16 @@
import type { ICommandInfo, IMutation } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
+import type { FormulaExecutedStateType, IExecutionInProgressParams } from '@univerjs/engine-formula';
import type { IAccessor } from '@wendellhu/redi';
export interface ISetFormulaCalculationStartMutation {
commands: ICommandInfo[];
+ forceCalculation?: boolean;
}
-
+/**
+ * TODO: @DR-Univer
+ * Trigger the calculation of the formula and stop the formula
+ */
export const setFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation> = {
id: 'formula.mutation.set-formula-calculation-start',
type: CommandType.MUTATION,
@@ -19,3 +24,14 @@ export const setFormulaCalculationStopMutation: IMutation<ISetFormulaCalculation
type: CommandType.MUTATION,
handler: (accessor: IAccessor, params: ISetFormulaCalculationStopMutation) => true,
};
+
+export interface ISetFormulaCalculationNotificationMutation {
+ functionsExecutedState?: FormulaExecutedStateType;
+ stageInfo?: IExecutionInProgressParams;
+}
+
+export const setFormulaCalculationNotificationMutation: IMutation<ISetFormulaCalculationNotificationMutation> = {
+ id: 'formula.mutation.set-formula-calculation-notification',
+ type: CommandType.MUTATION,
+ handler: (accessor: IAccessor, params: ISetFormulaCalculationNotificationMutation) => true,
+};
diff --git a/packages/formula/src/controllers/calculate.controller.ts b/packages/formula/src/controllers/calculate.controller.ts
index eee1ba3cd1..d165407cc5 100644
--- a/packages/formula/src/controllers/calculate.controller.ts
+++ b/packages/formula/src/controllers/calculate.controller.ts
@@ -11,7 +11,6 @@ import {
import type { IAllRuntimeData, IDirtyUnitSheetNameMap, IFormulaData } from '@univerjs/engine-formula';
import { FormulaEngineService, FormulaExecutedStateType } from '@univerjs/engine-formula';
import type {
- IAddWorksheetMergeMutationParams,
IDeleteRangeMutationParams,
IMoveColumnsMutationParams,
IMoveRangeMutationParams,
@@ -19,12 +18,11 @@ import type {
IRemoveRowsMutationParams,
IRemoveSheetMutationParams,
ISetRangeValuesMutationParams,
- ISetWorksheetNameMutationParams,
} from '@univerjs/sheets';
import {
- AddWorksheetMergeMutation,
DeleteRangeMutation,
InsertRangeMutation,
+ InsertSheetMutation,
MoveColsMutation,
MoveRangeMutation,
MoveRowsMutation,
@@ -33,7 +31,6 @@ import {
RemoveSheetMutation,
SetRangeValuesMutation,
SetStyleCommand,
- SetWorksheetNameMutation,
} from '@univerjs/sheets';
import { Inject } from '@wendellhu/redi';
import type { Nullable } from 'vitest';
@@ -41,7 +38,11 @@ import type { Nullable } from 'vitest';
import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import type { ISetFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
-import { setFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
+import {
+ setFormulaCalculationNotificationMutation,
+ setFormulaCalculationStartMutation,
+ setFormulaCalculationStopMutation,
+} from '../commands/mutations/set-formula-calculation.mutation';
import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation';
import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
import { FormulaDataModel } from '../models/formula-data.model';
@@ -66,19 +67,27 @@ export class CalculateController extends Disposable {
this._commandExecutedListener();
this._initialExecuteFormulaListener();
this._registerFunctions();
+ this._initialExecuteFormulaProcessListener();
}
private _commandExecutedListener() {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (command.id === SetFormulaDataMutation.id) {
+ if (command.id === setFormulaCalculationStopMutation.id) {
+ this._formulaEngineService.stopFormulaExecution();
+ } else if (command.id === SetFormulaDataMutation.id) {
const formulaData = (command.params as ISetFormulaDataMutationParams).formulaData as IFormulaData;
this._formulaDataModel.setFormulaData(formulaData);
} else if (command.id === setFormulaCalculationStartMutation.id) {
const params = command.params as ISetFormulaCalculationStartMutation;
- const { dirtyRanges, dirtyNameMap } = this._generateDirty(params.commands);
- this._calculate(dirtyRanges, dirtyNameMap);
+ if (params.forceCalculation === true) {
+ this._calculate(true);
+ } else {
+ const { dirtyRanges, dirtyNameMap } = this._generateDirty(params.commands);
+
+ this._calculate(false, dirtyRanges, dirtyNameMap);
+ }
} else if (command.id === SetArrayFormulaDataMutation.id) {
const params = command.params as ISetArrayFormulaDataMutationParams;
@@ -125,13 +134,14 @@ export class CalculateController extends Disposable {
} else if (command.id === RemoveSheetMutation.id) {
const params = command.params as IRemoveSheetMutationParams;
this._getSheetMutationDirtyName(dirtyNameMap, params);
- } else if (command.id === SetWorksheetNameMutation.id) {
- const params = command.params as ISetWorksheetNameMutationParams;
- this._getSheetMutationDirtyName(dirtyNameMap, params, params.name);
- } else if (command.id === AddWorksheetMergeMutation.id) {
- const params = command.params as IAddWorksheetMergeMutationParams;
+ } else if (command.id === InsertSheetMutation.id) {
+ const params = command.params as IRemoveSheetMutationParams;
this._getSheetMutationDirtyName(dirtyNameMap, params);
}
+ // else if (command.id === SetWorksheetNameMutation.id) {
+ // const params = command.params as ISetWorksheetNameMutationParams;
+ // this._getSheetMutationDirtyName(dirtyNameMap, params, params.name);
+ // }
}
return {
@@ -386,9 +396,11 @@ export class CalculateController extends Disposable {
return dirtyRanges;
}
- private async _calculate(dirtyRanges: IUnitRange[], dirtyNameMap: IDirtyUnitSheetNameMap) {
- if (dirtyRanges.length === 0) return;
-
+ private async _calculate(
+ forceCalculate: boolean = false,
+ dirtyRanges: IUnitRange[] = [],
+ dirtyNameMap: IDirtyUnitSheetNameMap = {}
+ ) {
const formulaData = this._formulaDataModel.getFormulaData();
const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
@@ -398,12 +410,13 @@ export class CalculateController extends Disposable {
this._formulaEngineService.execute({
formulaData,
arrayFormulaCellData,
- forceCalculate: false,
+ forceCalculate,
dirtyRanges,
dirtyNameMap,
});
}
+ // Notification
private _initialExecuteFormulaListener() {
/**
* Assignment operation after formula calculation.
@@ -421,6 +434,39 @@ export class CalculateController extends Disposable {
case FormulaExecutedStateType.INITIAL:
break;
}
+
+ this._commandService.executeCommand(setFormulaCalculationNotificationMutation.id, {
+ functionsExecutedState,
+ });
+ });
+ }
+
+ private _initialExecuteFormulaProcessListener() {
+ /**
+ * Assignment operation after formula calculation.
+ */
+ this._formulaEngineService.executionInProgressListener$.subscribe((data) => {
+ const {
+ totalFormulasToCalculate,
+ completedFormulasCount,
+ totalArrayFormulasToCalculate,
+ completedArrayFormulasCount,
+ stage,
+ } = data;
+
+ if (totalArrayFormulasToCalculate > 0) {
+ console.log(
+ `Stage ${stage} Array formula.There are ${totalArrayFormulasToCalculate} functions to be executed, ${completedArrayFormulasCount} complete.`
+ );
+ } else {
+ console.log(
+ `Stage ${stage} .There are ${totalFormulasToCalculate} functions to be executed, ${completedFormulasCount} complete.`
+ );
+ }
+
+ this._commandService.executeCommand(setFormulaCalculationNotificationMutation.id, {
+ stageInfo: data,
+ });
});
}
diff --git a/packages/formula/src/controllers/formula.controller.ts b/packages/formula/src/controllers/formula.controller.ts
index 35d1546ed7..16b6bf73f0 100644
--- a/packages/formula/src/controllers/formula.controller.ts
+++ b/packages/formula/src/controllers/formula.controller.ts
@@ -2,6 +2,7 @@ import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univ
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import {
+ setFormulaCalculationNotificationMutation,
setFormulaCalculationStartMutation,
setFormulaCalculationStopMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
@@ -25,6 +26,7 @@ export class FormulaController extends Disposable {
SetArrayFormulaDataMutation,
setFormulaCalculationStartMutation,
setFormulaCalculationStopMutation,
+ setFormulaCalculationNotificationMutation,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
}
diff --git a/packages/formula/src/controllers/trigger-calculation.controller.ts b/packages/formula/src/controllers/trigger-calculation.controller.ts
index 214119789f..7ffdce90f8 100644
--- a/packages/formula/src/controllers/trigger-calculation.controller.ts
+++ b/packages/formula/src/controllers/trigger-calculation.controller.ts
@@ -3,9 +3,9 @@ import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univ
import { FormulaEngineService, FormulaExecutedStateType } from '@univerjs/engine-formula';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import {
- AddWorksheetMergeMutation,
DeleteRangeMutation,
InsertRangeMutation,
+ InsertSheetMutation,
MoveColsMutation,
MoveRangeMutation,
MoveRowsMutation,
@@ -14,11 +14,14 @@ import {
RemoveSheetMutation,
SetRangeValuesMutation,
SetStyleCommand,
- SetWorksheetNameMutation,
} from '@univerjs/sheets';
import { Inject } from '@wendellhu/redi';
-import { setFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
+import type { ISetFormulaCalculationNotificationMutation } from '../commands/mutations/set-formula-calculation.mutation';
+import {
+ setFormulaCalculationNotificationMutation,
+ setFormulaCalculationStartMutation,
+} from '../commands/mutations/set-formula-calculation.mutation';
const globalObject = typeof self !== 'undefined' ? self : window;
@@ -28,6 +31,8 @@ export class TriggerCalculationController extends Disposable {
private _setTimeoutKey: number = -1;
+ private _startExecutionTime: number = 0;
+
constructor(
@ICommandService private readonly _commandService: ICommandService,
@Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService
@@ -40,8 +45,6 @@ export class TriggerCalculationController extends Disposable {
private _initialize(): void {
this._commandExecutedListener();
- this._initialExecuteFormulaResultListener();
-
this._initialExecuteFormulaProcessListener();
}
@@ -56,8 +59,8 @@ export class TriggerCalculationController extends Disposable {
RemoveRowMutation.id,
RemoveColMutation.id,
RemoveSheetMutation.id,
- SetWorksheetNameMutation.id,
- AddWorksheetMergeMutation.id,
+ // SetWorksheetNameMutation.id,
+ InsertSheetMutation.id,
];
this.disposeWithMe(
@@ -82,54 +85,65 @@ export class TriggerCalculationController extends Disposable {
this._commandService.executeCommand(setFormulaCalculationStartMutation.id, {
commands: this._waitingCommandQueue,
});
+
+ this._startExecutionTime = performance.now();
}, 100);
})
);
}
- private _initialExecuteFormulaResultListener() {
- /**
- * Assignment operation after formula calculation.
- */
- this._formulaEngineService.executionCompleteListener$.subscribe((data) => {
- const functionsExecutedState = data.functionsExecutedState;
- switch (functionsExecutedState) {
- case FormulaExecutedStateType.NOT_EXECUTED:
- break;
- case FormulaExecutedStateType.STOP_EXECUTION:
- break;
- case FormulaExecutedStateType.SUCCESS:
- this._waitingCommandQueue = [];
- console.log(`functions execute complete.`);
- break;
- case FormulaExecutedStateType.INITIAL:
- break;
- }
- });
- }
-
private _initialExecuteFormulaProcessListener() {
/**
* Assignment operation after formula calculation.
*/
- this._formulaEngineService.executionInProgressListener$.subscribe((data) => {
- const {
- totalFormulasToCalculate,
- completedFormulasCount,
- totalArrayFormulasToCalculate,
- completedArrayFormulasCount,
- stage,
- } = data;
-
- if (totalArrayFormulasToCalculate > 0) {
- console.log(
- `Stage ${stage} Array formula.There are ${totalArrayFormulasToCalculate} functions to be executed, ${completedArrayFormulasCount} complete.`
- );
- } else {
- console.log(
- `Stage ${stage} .There are ${totalFormulasToCalculate} functions to be executed, ${completedFormulasCount} complete.`
- );
- }
- });
+
+ this.disposeWithMe(
+ this._commandService.onCommandExecuted((command: ICommandInfo) => {
+ if (command.id !== setFormulaCalculationNotificationMutation.id) {
+ return;
+ }
+
+ const params = command.params as ISetFormulaCalculationNotificationMutation;
+
+ if (params.stageInfo != null) {
+ const {
+ totalFormulasToCalculate,
+ completedFormulasCount,
+ totalArrayFormulasToCalculate,
+ completedArrayFormulasCount,
+ stage,
+ } = params.stageInfo;
+ if (totalArrayFormulasToCalculate > 0) {
+ console.log(
+ `Stage ${stage} Array formula.There are ${totalArrayFormulasToCalculate} functions to be executed, ${completedArrayFormulasCount} complete.`
+ );
+ } else {
+ console.log(
+ `Stage ${stage} .There are ${totalFormulasToCalculate} functions to be executed, ${completedFormulasCount} complete.`
+ );
+ }
+ } else {
+ const state = params.functionsExecutedState;
+ let result = '';
+ switch (state) {
+ case FormulaExecutedStateType.NOT_EXECUTED:
+ result = 'No tasks are being executed anymore';
+ break;
+ case FormulaExecutedStateType.STOP_EXECUTION:
+ result = 'The execution of the formula has been stopped';
+ break;
+ case FormulaExecutedStateType.SUCCESS:
+ result = `Formula calculation succeeded, Total time consumed: ${
+ performance.now() - this._startExecutionTime
+ } ms`;
+ break;
+ case FormulaExecutedStateType.INITIAL:
+ result = 'Waiting for calculation';
+ break;
+ }
+ console.log(`execution result${result}`);
+ }
+ })
+ );
}
}
diff --git a/packages/formula/src/formula-plugin.ts b/packages/formula/src/formula-plugin.ts
index e900ee8e80..e1056af789 100644
--- a/packages/formula/src/formula-plugin.ts
+++ b/packages/formula/src/formula-plugin.ts
@@ -34,15 +34,17 @@ export class FormulaPlugin extends Plugin {
[FormulaDataModel, { useValue: this._formulaDataModel }],
// controllers
[FormulaController],
- [UpdateFormulaController],
- [ArrayFormulaDisplayController],
- [TriggerCalculationController],
];
- // only worker
if (!this._config?.notExecuteFormula) {
+ // only worker
dependencies.push([IFormulaService, { useClass: FormulaService }]);
dependencies.push([CalculateController]);
+ } else {
+ // only main thread
+ dependencies.push([UpdateFormulaController]);
+ dependencies.push([ArrayFormulaDisplayController]);
+ dependencies.push([TriggerCalculationController]);
}
dependencies.forEach((dependency) => this._injector.add(dependency));
diff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.ts
index 6ace1ae5fd..d3fbd4eba9 100644
--- a/packages/sheets-formula/src/controllers/prompt.controller.ts
+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts
@@ -876,7 +876,7 @@ export class PromptController extends Disposable {
const refSheetId = this._getSheetIdByName(unitId, sheetName.trim());
- if (refSheetId != null && refSheetId !== sheetId) {
+ if (refSheetId !== sheetId) {
continue;
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 965ffc297e..095d57897e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -700,6 +700,9 @@ importers:
'@wendellhu/redi':
specifier: ^0.12.11
version: 0.12.11
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
devDependencies:
'@vitest/coverage-istanbul':
specifier: ^0.34.6