Clone WI cache only on get
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | 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'; |
| 2 | 2 | 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'; |
| 3 | 3 | import { extension_settings, getContext } from './extensions.js'; |
| 4 | 4 | import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js'; |
| 5 | 5 | import { isMobile } from './RossAscends-mods.js'; |
| @@ -748,7 +748,7 @@ export const wi_anchor_position = { | ||
| 748 | 748 | }; |
| 749 | 749 | |
| 750 | 750 | /** @type {StructuredCloneMap<string,object>} */ |
| 751 | 751 | const worldInfoCache = new StructuredCloneMap({ cloneOnGet: true, cloneOnSet: false }); |
| 752 | 752 | |
| 753 | 753 | /** |
| 754 | 754 | * Gets the world info based on chat messages. |
| @@ -2898,8 +2898,6 @@ function getWorldEntry(name, data, entry) { | ||
| 2898 | 2898 | .prop('selected', true) |
| 2899 | 2899 | .trigger('input'); |
| 2900 | 2900 | |
| 2901 | - saveWorldInfo(name, data); | |
| 2902 | - | |
| 2903 | 2901 | // exclude recursion |
| 2904 | 2902 | const excludeRecursionInput = template.find('input[name="exclude_recursion"]'); |
| 2905 | 2903 | excludeRecursionInput.data('uid', entry.uid); |
| @@ -3269,6 +3267,9 @@ function createWorldInfoEntry(_name, data) { | ||
| 3269 | 3267 | } |
| 3270 | 3268 | |
| 3271 | 3269 | async function _save(name, data) { |
| 3270 | + // Prevent double saving if both immediate and debounced save are called | |
| 3271 | + cancelDebounce(saveWorldDebounced); | |
| 3272 | + | |
| 3272 | 3273 | await fetch('/api/worldinfo/edit', { |
| 3273 | 3274 | method: 'POST', |
| 3274 | 3275 | headers: getRequestHeaders(), |