Calculate entry hash before replacing macros Fixes #2762

7a7673432a2168f45fe2b5759cd2e7d9907eb79f

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +5 -15Showing whitespace changes
public/scripts/world-info.js+5 -15
@@ -108,6 +108,7 @@ const KNOWN_DECORATORS = ['@@activate', '@@dont_activate'];
108108 * @property {number} [cooldown] The cooldown of the entry
109109 * @property {number} [delay] The delay of the entry
110110 * @property {string[]} [decorators] Array of decorators for the entry
111+ * @property {number} [hash] The hash of the entry
111112 */
112113
113114/**
@@ -383,12 +384,6 @@ class WorldInfoBuffer {
383384 */
384385class WorldInfoTimedEffects {
385386 /**
386- * Cache for entry hashes. Uses weak map to avoid memory leaks.
387- * @type {WeakMap<WIScanEntry, number>}
388- */
389- #entryHashCache = new WeakMap();
390-
391- /**
392387 * Array of chat messages.
393388 * @type {string[]}
394389 */
@@ -485,13 +480,7 @@ class WorldInfoTimedEffects {
485480 * @returns {number} String hash
486481 */
487482 #getEntryHash(entry) {
488- if (this.#entryHashCache.has(entry)) {
483+ return entry.hash;
489- return this.#entryHashCache.get(entry);
490- }
491-
492- const hash = getStringHash(JSON.stringify(entry));
493- this.#entryHashCache.set(entry, hash);
494- return hash;
495484 }
496485
497486 /**
@@ -3603,10 +3592,11 @@ export async function getSortedEntries() {
36033592 // Chat lore always goes first
36043593 entries = [...chatLore.sort(sortFn), ...entries];
36053594
36063595 // ParseCalculate hash and parse decorators
36073596 entries = entries.map((entry) => {
3597+ const hash = getStringHash(JSON.stringify(entry));
36083598 const [decorators, content] = parseDecorators(entry.content || '');
36093599 return { ...entry, decorators, content, hash };
36103600 });
36113601
36123602 console.debug(`[WI] Found ${entries.length} world lore entries. Sorted by strategy`, Object.entries(world_info_insertion_strategy).find((x) => x[1] === world_info_character_strategy));