From 106f7afdcbe61eb92a5d50c921820c2b09cc4f2a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 20 Aug 2023 13:15:02 +0300 Subject: [PATCH] Slight performance increase for opening large World Infos --- public/index.html | 6 ++---- public/scripts/extensions/expressions/index.js | 2 +- public/scripts/group-chats.js | 5 +++++ public/scripts/world-info.js | 17 +++++++++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/public/index.html b/public/index.html index 695de9556..3b38ee720 100644 --- a/public/index.html +++ b/public/index.html @@ -3713,9 +3713,7 @@ Content - (Tokens:  - 0 - ) + (Tokens:  counting...) @@ -4356,4 +4354,4 @@ - \ No newline at end of file + diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index 52715ea99..e9ceca7c4 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -499,7 +499,7 @@ async function moduleWorker() { const context = getContext(); // non-characters not supported - if (!context.groupId && context.characterId === undefined) { + if (!context.groupId && (context.characterId === undefined || context.characterId === 'invalid-safety-id')) { removeExpression(); return; } diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index f993d2449..108c03aa3 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -1263,6 +1263,11 @@ function updateFavButtonState(state) { } export async function openGroupById(groupId) { + if (!groups.find(x => x.id === groupId)) { + console.log('Group not found', groupId); + return; + } + if (!is_send_press && !is_group_generating) { if (selected_group !== groupId) { cancelTtsPlay(); diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 9b09a3505..895dd56af 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -464,7 +464,7 @@ function appendWorldEntry(name, data, entry) { const contentInput = template.find('textarea[name="content"]'); contentInput.data("uid", entry.uid); - contentInput.on("input", function () { + contentInput.on("input", function (_, { skipCount }) { const uid = $(this).data("uid"); const value = $(this).val(); data.entries[uid].content = value; @@ -472,12 +472,25 @@ function appendWorldEntry(name, data, entry) { setOriginalDataValue(data, uid, "content", data.entries[uid].content); saveWorldInfo(name, data); + if (skipCount) { + return; + } + // count tokens countTokensDebounced(this, value); }); - contentInput.val(entry.content).trigger("input"); + contentInput.val(entry.content).trigger("input", { skipCount: true }); //initScrollHeight(contentInput); + template.find('.inline-drawer-toggle').on('click', function () { + const counter = template.find(".world_entry_form_token_counter"); + + if (counter.data('first-run')) { + counter.data('first-run', false); + countTokensDebounced(contentInput, contentInput.val()); + } + }); + // selective const selectiveInput = template.find('input[name="selective"]'); selectiveInput.data("uid", entry.uid);