feat(data-validation): add 'set' property to IListCacheItem for improved caching (#6229)

This commit is contained in:
WEI ZHANG
2025-12-01 19:25:24 +08:00
committed by GitHub
parent 2bc292903d
commit a4c88b810f
2 changed files with 10 additions and 4 deletions
@@ -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;
@@ -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));
}