Clone WI cache only on get

1e2293713d14d39b630ce1dee8a45393d5346a78

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +5 -4Showing whitespace changes
public/scripts/world-info.js+5 -4
@@ -1,5 +1,5 @@
11import { saveSettings, callPopup, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js';
22import { 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';
33import { extension_settings, getContext } from './extensions.js';
44import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js';
55import { isMobile } from './RossAscends-mods.js';
@@ -748,7 +748,7 @@ export const wi_anchor_position = {
748748};
749749
750750/** @type {StructuredCloneMap<string,object>} */
751751const worldInfoCache = new StructuredCloneMap({ cloneOnGet: true, cloneOnSet: false });
752752
753753/**
754754 * Gets the world info based on chat messages.
@@ -2898,8 +2898,6 @@ function getWorldEntry(name, data, entry) {
28982898 .prop('selected', true)
28992899 .trigger('input');
29002900
2901- saveWorldInfo(name, data);
2902-
29032901 // exclude recursion
29042902 const excludeRecursionInput = template.find('input[name="exclude_recursion"]');
29052903 excludeRecursionInput.data('uid', entry.uid);
@@ -3269,6 +3267,9 @@ function createWorldInfoEntry(_name, data) {
32693267}
32703268
32713269async function _save(name, data) {
3270+ // Prevent double saving if both immediate and debounced save are called
3271+ cancelDebounce(saveWorldDebounced);
3272+
32723273 await fetch('/api/worldinfo/edit', {
32733274 method: 'POST',
32743275 headers: getRequestHeaders(),