Pre-cache related WI entries on chat load

This commit is contained in:
Cohee
2024-06-23 18:50:40 +03:00
parent 39362fd566
commit 3dcb4dee59

View File

@@ -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)}]`,