Skip to content

Commit

Permalink
fix(sheets-data-validation): data-validation oom on extreme-big-range (
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 committed Sep 20, 2024
1 parent 9ddcaf5 commit 86c2dd9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/shared/__tests__/range.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ describe('mergeRanges', () => {
endRow: 10,
},
{
startColumn: 6,
startColumn: 4,
startRow: 8,
endColumn: 7,
endRow: 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ export const UpdateSheetDataValidationRangeCommand: ICommand<IUpdateSheetDataVal
if (!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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/sheets-data-validation/src/models/rule-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -85,7 +85,7 @@ export class RuleMatrix {
}
});

this._map.set(ruleId, _newRanges);
this._map.set(ruleId, ranges);
}

diff(rules: ISheetDataValidationRule[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) {
Expand Down

0 comments on commit 86c2dd9

Please sign in to comment.