mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-03 03:17:54 +01:00
parent
7c383e3218
commit
7a7673432a
@ -108,6 +108,7 @@ const KNOWN_DECORATORS = ['@@activate', '@@dont_activate'];
|
|||||||
* @property {number} [cooldown] The cooldown of the entry
|
* @property {number} [cooldown] The cooldown of the entry
|
||||||
* @property {number} [delay] The delay of the entry
|
* @property {number} [delay] The delay of the entry
|
||||||
* @property {string[]} [decorators] Array of decorators for the entry
|
* @property {string[]} [decorators] Array of decorators for the entry
|
||||||
|
* @property {number} [hash] The hash of the entry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -382,12 +383,6 @@ class WorldInfoBuffer {
|
|||||||
* Represents a timed effects manager for World Info.
|
* Represents a timed effects manager for World Info.
|
||||||
*/
|
*/
|
||||||
class WorldInfoTimedEffects {
|
class WorldInfoTimedEffects {
|
||||||
/**
|
|
||||||
* Cache for entry hashes. Uses weak map to avoid memory leaks.
|
|
||||||
* @type {WeakMap<WIScanEntry, number>}
|
|
||||||
*/
|
|
||||||
#entryHashCache = new WeakMap();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of chat messages.
|
* Array of chat messages.
|
||||||
* @type {string[]}
|
* @type {string[]}
|
||||||
@ -485,13 +480,7 @@ class WorldInfoTimedEffects {
|
|||||||
* @returns {number} String hash
|
* @returns {number} String hash
|
||||||
*/
|
*/
|
||||||
#getEntryHash(entry) {
|
#getEntryHash(entry) {
|
||||||
if (this.#entryHashCache.has(entry)) {
|
return entry.hash;
|
||||||
return this.#entryHashCache.get(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hash = getStringHash(JSON.stringify(entry));
|
|
||||||
this.#entryHashCache.set(entry, hash);
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3603,10 +3592,11 @@ export async function getSortedEntries() {
|
|||||||
// Chat lore always goes first
|
// Chat lore always goes first
|
||||||
entries = [...chatLore.sort(sortFn), ...entries];
|
entries = [...chatLore.sort(sortFn), ...entries];
|
||||||
|
|
||||||
// Parse decorators
|
// Calculate hash and parse decorators
|
||||||
entries = entries.map((entry) => {
|
entries = entries.map((entry) => {
|
||||||
|
const hash = getStringHash(JSON.stringify(entry));
|
||||||
const [decorators, content] = parseDecorators(entry.content || '');
|
const [decorators, content] = parseDecorators(entry.content || '');
|
||||||
return { ...entry, decorators, content };
|
return { ...entry, decorators, content, hash };
|
||||||
});
|
});
|
||||||
|
|
||||||
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));
|
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));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user