Skip to content

Commit

Permalink
fix(formula): fix ArrayValueObject compare cache bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 authored and wpxp123456 committed Oct 16, 2024
1 parent 9629283 commit 13f3474
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/engine-formula/src/services/runtime.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type { ArrayValueObject } from '../engine/value-object/array-value-object
import { createIdentifier, Disposable, isNullCell, ObjectMatrix } from '@univerjs/core';
import { isInDirtyRange } from '../basics/dirty';
import { ErrorType } from '../basics/error-type';
import { CELL_INVERTED_INDEX_CACHE } from '../basics/inverted-index-cache';
import { getRuntimeFeatureCell } from '../engine/utils/get-runtime-feature-cell';
import { objectValueToCellValue } from '../engine/utils/value-object';
import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';
Expand Down Expand Up @@ -501,6 +502,15 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
sheetData.setValue(row, column, valueObject);
clearArrayUnitData.setValue(row, column, valueObject);

// Formula calculation results are saved to cache
CELL_INVERTED_INDEX_CACHE.set(
unitId,
sheetId,
column,
firstCell.getValue(),
row
);

return;
}

Expand All @@ -523,6 +533,15 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
sheetData.setValue(row, column, errorObject);
clearArrayUnitData.setValue(row, column, errorObject);

// Formula calculation results are saved to cache
CELL_INVERTED_INDEX_CACHE.set(
unitId,
sheetId,
column,
ErrorType.SPILL,
row
);

/**
* When there are values within the array formula range, the entire formula will result in an error.
* In this case, you need to clear the previous range data to prevent other formulas from referencing the old values.
Expand Down Expand Up @@ -550,6 +569,15 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
} else {
const spillError = ErrorValueObject.create(ErrorType.SPILL);
objectValueRefOrArray.iterator((valueObject, rowIndex, columnIndex) => {
// Formula calculation results are saved to cache
CELL_INVERTED_INDEX_CACHE.set(
unitId,
sheetId,
column - startColumn + columnIndex,
!valueObject ? 0 : valueObject.getValue(),
row - startRow + rowIndex
);

const value = objectValueToCellValue(valueObject);
if (rowIndex === startRow && columnIndex === startColumn) {
/**
Expand All @@ -574,6 +602,15 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
const valueObject = objectValueToCellValue(functionVariant as BaseValueObject);
sheetData.setValue(row, column, valueObject);

// Formula calculation results are saved to cache
CELL_INVERTED_INDEX_CACHE.set(
unitId,
sheetId,
column,
(functionVariant as BaseValueObject).getValue(),
row
);

clearArrayUnitData.setValue(row, column, valueObject);
}
}
Expand Down

0 comments on commit 13f3474

Please sign in to comment.