From 86c2dd94e94f1cc1f7d8de612204f832ea62942f Mon Sep 17 00:00:00 2001 From: zhangw Date: Fri, 20 Sep 2024 10:35:48 +0800 Subject: [PATCH] fix(sheets-data-validation): data-validation oom on extreme-big-range (#3494) --- packages/core/src/shared/__tests__/range.spec.ts | 2 +- .../src/commands/commands/data-validation.command.ts | 3 +-- .../src/controllers/dv-copy-paste.controller.ts | 8 +++++++- .../src/controllers/dv-ref-range.controller.ts | 5 +++-- packages/sheets-data-validation/src/models/rule-matrix.ts | 4 ++-- .../src/models/sheet-data-validation-model.ts | 4 ++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/core/src/shared/__tests__/range.spec.ts b/packages/core/src/shared/__tests__/range.spec.ts index ab0b040c854..65ad69b4a6a 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.ts index 7a5ec37ff7a..bdbf977b77f 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(); 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.ts index 996abdb16f5..9131c0234d7 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 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.ts index 2814e76b8fe..b8a3c978f85 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.ts index a046096b533..9cbca568036 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) {