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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-data-validation): data-validation oom on extreme-big-range (#3494)
zhangw86c2dd94e94f
diff --git a/packages/core/src/shared/__tests__/range.spec.ts b/packages/core/src/shared/__tests__/range.spec.tsindex ab0b040c85..65ad69b4a6 100644--- a/packages/core/src/shared/__tests__/range.spec.ts+++ b/packages/core/src/shared/__tests__/range.spec.ts@@ -394,7 +394,7 @@ describe('mergeRanges', () => {endRow: 10,},{- startColumn: 6,+ startColumn: 4,startRow: 8,endColumn: 7,endRow: 8,diff --git a/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts b/packages/sheets-data-validation/src/commands/commands/data-validation.command.tsindex 7a5ec37ff7..bdbf977b77 100644--- a/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts+++ b/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts@@ -216,9 +216,8 @@ export const UpdateSheetDataValidationRangeCommand: ICommand<IUpdateSheetDataValif (!currentRule) {return false;}- const oldRanges = currentRule.ranges;const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();- matrix.updateRange(ruleId, oldRanges, ranges);+ matrix.updateRange(ruleId, ranges);const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId));const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);diff --git a/packages/sheets-data-validation/src/controllers/dv-copy-paste.controller.ts b/packages/sheets-data-validation/src/controllers/dv-copy-paste.controller.tsindex fffe3337ec..cc5291ab6e 100644--- a/packages/sheets-data-validation/src/controllers/dv-copy-paste.controller.ts+++ b/packages/sheets-data-validation/src/controllers/dv-copy-paste.controller.ts@@ -114,6 +114,8 @@ export class DataValidationCopyPasteController extends Disposable {if (copyInfo.unitId !== unitId || subUnitId !== copyInfo.subUnitId) {const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyInfo.unitId, copyInfo.subUnitId).clone();+ const additionMatrix = new ObjectMatrix();+ const addRules = new Set<string>();const { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyInfo.copyRange, pastedRange]);@@ -139,10 +141,14 @@ export class DataValidationCopyPasteController extends Disposable {}const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);- // ruleMatrix.setValue(startRow, startColumn, transformedRuleId);+ addRules.add(transformedRuleId);+ additionMatrix.setValue(startRow, startColumn, transformedRuleId);});});+ const additions = Array.from(addRules).map((id) => ({ id, ranges: queryObjectMatrix(additionMatrix, (value) => value === id) }));+ ruleMatrix.addRangeRules(additions);+const { redoMutations, undoMutations } = getDataValidationDiffMutations(copyInfo.unitId,copyInfo.subUnitId,diff --git a/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts b/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.tsindex 996abdb16f..9131c0234d 100644--- a/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts+++ b/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts@@ -15,13 +15,14 @@*/import { DataValidationType, Disposable, Inject, Injector, isRangesEqual, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';-import { DataValidationModel, RemoveDataValidationMutation, UpdateDataValidationMutation, UpdateRuleType } from '@univerjs/data-validation';+import { RemoveDataValidationMutation, UpdateDataValidationMutation, UpdateRuleType } from '@univerjs/data-validation';import { handleCommonDefaultRangeChangeWithEffectRefCommands, RefRangeService } from '@univerjs/sheets';import { FormulaRefRangeService } from '@univerjs/sheets-formula';import type { IRange, ISheetDataValidationRule } from '@univerjs/core';import type { IRemoveDataValidationMutationParams, IUpdateDataValidationMutationParams } from '@univerjs/data-validation';import type { EffectRefRangeParams } from '@univerjs/sheets';import { removeDataValidationUndoFactory } from '../commands/commands/data-validation.command';+import { SheetDataValidationModel } from '../models/sheet-data-validation-model';import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';import { DataValidationFormulaService } from '../services/dv-formula.service';@@ -30,7 +31,7 @@ export class DataValidationRefRangeController extends Disposable {private _disposableMap: Map<string, Set<() => void>> = new Map();constructor(- @Inject(DataValidationModel) private _dataValidationModel: DataValidationModel,+ @Inject(SheetDataValidationModel) private _dataValidationModel: SheetDataValidationModel,@Inject(Injector) private _injector: Injector,@Inject(RefRangeService) private _refRangeService: RefRangeService,@Inject(DataValidationCustomFormulaService) private _dataValidationCustomFormulaService: DataValidationCustomFormulaService,diff --git a/packages/sheets-data-validation/src/models/rule-matrix.ts b/packages/sheets-data-validation/src/models/rule-matrix.tsindex 2814e76b8f..b8a3c978f8 100644--- a/packages/sheets-data-validation/src/models/rule-matrix.ts+++ b/packages/sheets-data-validation/src/models/rule-matrix.ts@@ -73,7 +73,7 @@ export class RuleMatrix {this._map.delete(rule.uid);}- updateRange(ruleId: string, _oldRanges: IRange[], _newRanges: IRange[]) {+ updateRange(ruleId: string, _newRanges: IRange[]) {this._map.delete(ruleId);const ranges = _newRanges.map((range) => Range.transformRange(range, this._worksheet));this._map.forEach((value, key) => {@@ -85,7 +85,7 @@ export class RuleMatrix {}});- this._map.set(ruleId, _newRanges);+ this._map.set(ruleId, ranges);}diff(rules: ISheetDataValidationRule[]) {diff --git a/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts b/packages/sheets-data-validation/src/models/sheet-data-validation-model.tsindex a046096b53..9cbca56803 100644--- a/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts+++ b/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts@@ -125,7 +125,7 @@ export class SheetDataValidationModel extends Disposable {this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, rule);}- private _addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule | ISheetDataValidationRule[], index?: number): void {+ private _addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule | ISheetDataValidationRule[]): void {const rules = Array.isArray(rule) ? rule : [rule];rules.forEach((item) => {@@ -136,7 +136,7 @@ export class SheetDataValidationModel extends Disposable {private _updateRule(unitId: string, subUnitId: string, ruleId: string, oldRule: ISheetDataValidationRule, payload: IUpdateRulePayload) {const ruleMatrix = this._ensureRuleMatrix(unitId, subUnitId);if (payload.type === UpdateRuleType.RANGE) {- ruleMatrix.updateRange(ruleId, oldRule.ranges, payload.payload);+ ruleMatrix.updateRange(ruleId, payload.payload);this._dataValidationCacheService.updateRuleRanges(unitId, subUnitId, ruleId, payload.payload, oldRule.ranges);this._dataValidationCustomFormulaService.updateRuleRanges(unitId, subUnitId, ruleId, oldRule.ranges, payload.payload);} else if (payload.type === UpdateRuleType.SETTING) {