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
feat(data-validation): add 'set' property to IListCacheItem for improved caching (#6229)
WEI ZHANGa4c88b810f5c
diff --git a/packages/sheets-data-validation/src/services/dv-list-cache.service.ts b/packages/sheets-data-validation/src/services/dv-list-cache.service.tsindex a455ad955b..f4287889fb 100644--- a/packages/sheets-data-validation/src/services/dv-list-cache.service.ts+++ b/packages/sheets-data-validation/src/services/dv-list-cache.service.ts@@ -27,6 +27,7 @@ export interface IListCacheItem {list: string[];listWithColor: Array<{ label: string; color: string }>;colorMap: Record<string, string>;+ set: Set<string>;}type UnitId = string;@@ -151,8 +152,8 @@ export class DataValidationListCacheService extends Disposable {colorMap[item.label] = item.color;}}-- const cacheItem: IListCacheItem = { list, listWithColor, colorMap };+ const set = new Set(list);+ const cacheItem: IListCacheItem = { list, listWithColor, colorMap, set };this.setCache(unitId, subUnitId, rule.uid, cacheItem);return cacheItem;diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.tsindex a23d029f87..d49939c0c5 100644--- a/packages/sheets-data-validation/src/validators/list-validator.ts+++ b/packages/sheets-data-validation/src/validators/list-validator.ts@@ -170,8 +170,13 @@ export class ListValidator extends BaseDataValidator {override async isValidType(cellInfo: IValidatorCellInfo<Nullable<CellValue>>, formula: IFormulaResult<string[] | undefined>, rule: IDataValidationRule): Promise<boolean> {const { value, unitId, subUnitId } = cellInfo;const { formula1 = '' } = rule;- const results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);- const formula1Result = isFormulaString(formula1) ? getRuleFormulaResultSet(results?.[0]?.result?.[0][0]) : deserializeListOptions(formula1);+ const formula1Result = isFormulaString(formula1)+ ? this._listCacheService.getOrCompute(+ unitId,+ subUnitId,+ rule+ ).list+ : deserializeListOptions(formula1);const selected = this.parseCellValue(value!);return selected.every((i) => formula1Result.includes(i));}