mirror of
https://github.com/dream-num/univer.git
synced 2026-08-29 07:13:59 +08:00
feat(data-validation): add 'set' property to IListCacheItem for improved caching (#6229)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user