From 3dcb4dee593e027273007ebf77ece97d43ba3ddf Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 23 Jun 2024 18:50:40 +0300 Subject: [PATCH] Pre-cache related WI entries on chat load --- public/scripts/world-info.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 4f02ab0d3..d632015d0 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -742,9 +742,11 @@ function setWorldInfoSettings(settings, data) { $('#world_info').trigger('change'); $('#world_editor_select').trigger('change'); - eventSource.on(event_types.CHAT_CHANGED, () => { + eventSource.on(event_types.CHAT_CHANGED, async () => { const hasWorldInfo = !!chat_metadata[METADATA_KEY] && world_names.includes(chat_metadata[METADATA_KEY]); $('.chat_lorebook_button').toggleClass('world_set', hasWorldInfo); + // Pre-cache the world info data for the chat for quicker first prompt generation + await getSortedEntries(); }); eventSource.on(event_types.WORLDINFO_FORCE_ACTIVATE, (entries) => { @@ -978,7 +980,8 @@ function registerWorldInfoSlashCommands() { const file = executor.namedArgumentList.find(it => it.name == 'file')?.value; if (file instanceof SlashCommandClosure) throw new Error('Argument \'file\' does not support closures'); // Try find world from cache - const world = worldInfoCache[file]; + if (!worldInfoCache.has(file)) return []; + const world = worldInfoCache.get(file); if (!world) return []; return Object.entries(world.entries).map(([uid, data]) => new SlashCommandEnumValue(uid, `${data.comment ? `${data.comment}: ` : ''}${data.key.join(', ')}${data.keysecondary?.length ? ` [${Object.entries(world_info_logic).find(([_, value]) => value == data.selectiveLogic)[0]}] ${data.keysecondary.join(', ')}` : ''} [${getWiPositionString(data)}]`,