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.

fix(sheets-data-validation): performance issues when edit whole cells on large scale (#5727)

WEI ZHANG128cdc8056a9
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 21cc6b0816..449b0941ef 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -57,5 +57,10 @@
"editor.quickSuggestions": {
"strings": "on"
- }
+ },
+ "cSpell.words": [
+ "mockdata",
+ "Univer",
+ "univerjs"
+ ]
}
diff --git a/packages/sheets-data-validation/src/services/dv-cache.service.ts b/packages/sheets-data-validation/src/services/dv-cache.service.ts
index 81040a43d7..beac892fd2 100644
--- a/packages/sheets-data-validation/src/services/dv-cache.service.ts
+++ b/packages/sheets-data-validation/src/services/dv-cache.service.ts
@@ -16,7 +16,8 @@
import type { DataValidationStatus, IRange, ISheetDataValidationRule, Nullable } from '@univerjs/core';
import type { IRemoveSheetMutationParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';
-import { Disposable, ICommandService, Inject, IUniverInstanceService, ObjectMatrix, Range, UniverInstanceType } from '@univerjs/core';
+import { Disposable, getIntersectRange, ICommandService, Inject, IUniverInstanceService, ObjectMatrix, Range, UniverInstanceType } from '@univerjs/core';
+import { DataValidationModel } from '@univerjs/data-validation';
import { RemoveSheetMutation, SetRangeValuesMutation } from '@univerjs/sheets';
import { Subject } from 'rxjs';
@@ -28,7 +29,8 @@ export class DataValidationCacheService extends Disposable {
constructor(
@Inject(ICommandService) private readonly _commandService: ICommandService,
- @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService
+ @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(DataValidationModel) private readonly _sheetDataValidationModel: DataValidationModel
) {
super();
this._initDirtyRanges();
@@ -42,7 +44,12 @@ export class DataValidationCacheService extends Disposable {
if (cellValue) {
const range = new ObjectMatrix(cellValue).getDataRange();
if (range.endRow === -1) return;
- this.markRangeDirty(unitId, subUnitId, [range], true);
+ const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
+ const ranges = rules.map((rule) => rule.ranges).flat();
+ const intersectsRanges = ranges.map((ruleRange) => getIntersectRange(ruleRange, range)).filter(Boolean) as IRange[];
+ if (intersectsRanges.length) {
+ this.markRangeDirty(unitId, subUnitId, intersectsRanges, true);
+ }
}
}
}));