ハッシュ計算関数にフィールド引数を追加, k-tune'でコンフィギュレーションを変更すると、キャッシュも無効になります。

This commit is contained in:
Mouriya
2024-09-19 21:17:30 +09:00
parent 7ec2b6df28
commit 32ffee0c93

View File

@@ -45,7 +45,7 @@ interface IField {
label: string;
}
// ドロップダウンメニューの<EFBFBD><EFBFBD><EFBFBD>書タイプ、ドロップダウンオプションの検索を高速化するために使用
// ドロップダウンメニューの書タイプ、ドロップダウンオプションの検索を高速化するために使用
// キーの形式は: ドロップダウンメニューの階層_value
// 例: 2番目の階層で結果aを選択した場合、1_aを使用して、値aの次の階層3番目の階層のオプションを取得できます
type DropdownDictionary = Record<string, string[]>;
@@ -67,8 +67,8 @@ namespace DropDownConfig {
});
// ドロップダウンメニューの辞書を一度構築するコストが高いため、レコードのハッシュ値を計算してキャッシュキーとして使用
// kintoneのデータが変更されていない場合、辞書を再構築<EFBFBD><EFBFBD><EFBFBD>る必要はありません
const hash = await calculateHash(records);
// kintoneのデータが変更されていない場合、辞書を再構築る必要はありません
const hash = await calculateHash(records, fields);
const storageKey = `dropdown_dictionary::${props.dropDownApp.id}_${hash}`;
// ローカルストレージから辞書を取得しようとし、存在しない場合は再構築
@@ -88,8 +88,11 @@ namespace DropDownConfig {
};
// Web Crypto APIを使用してハッシュ値を計算
const calculateHash = async (records: KTRecord[]): Promise<string> => {
const str = JSON.stringify(records);
const calculateHash = async (
records: KTRecord[],
fields: string[]
): Promise<string> => {
const str = JSON.stringify(records) + JSON.stringify(fields);
const encoder = new TextEncoder();
const data = encoder.encode(str);
const hashBuffer = await crypto.subtle.digest("SHA-1", data); // SHA-1を使用、パフォーマンスが良く、セキュリティは不要
@@ -193,9 +196,6 @@ export class CascadingDropDownAction implements IAction {
this.actionProps = actionNode.actionProps;
this.props = actionNode.ActionValue as ICascadingDropDownProps;
console.log(this.actionProps);
console.log(this.props);
const result: IActionResult = { canNext: true, result: "" };
try {