From 1e2293713d14d39b630ce1dee8a45393d5346a78 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 22 Jul 2024 22:34:53 +0300 Subject: [PATCH] Clone WI cache only on get --- public/scripts/world-info.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 0e12da10f..3e8ccab6f 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1,5 +1,5 @@ import { saveSettings, callPopup, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js'; -import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray } from './utils.js'; +import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce } from './utils.js'; import { extension_settings, getContext } from './extensions.js'; import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js'; import { isMobile } from './RossAscends-mods.js'; @@ -748,7 +748,7 @@ export const wi_anchor_position = { }; /** @type {StructuredCloneMap} */ -const worldInfoCache = new StructuredCloneMap(); +const worldInfoCache = new StructuredCloneMap({ cloneOnGet: true, cloneOnSet: false }); /** * Gets the world info based on chat messages. @@ -2898,8 +2898,6 @@ function getWorldEntry(name, data, entry) { .prop('selected', true) .trigger('input'); - saveWorldInfo(name, data); - // exclude recursion const excludeRecursionInput = template.find('input[name="exclude_recursion"]'); excludeRecursionInput.data('uid', entry.uid); @@ -3269,6 +3267,9 @@ function createWorldInfoEntry(_name, data) { } async function _save(name, data) { + // Prevent double saving if both immediate and debounced save are called + cancelDebounce(saveWorldDebounced); + await fetch('/api/worldinfo/edit', { method: 'POST', headers: getRequestHeaders(),