Slight performance increase for opening large World Infos

This commit is contained in:
Cohee 2023-08-20 13:15:02 +03:00
parent b44c72c639
commit 106f7afdcb
4 changed files with 23 additions and 7 deletions

View File

@ -3713,9 +3713,7 @@
<small>
<span data-i18n="Content">
Content
<span>(Tokens:&nbsp;
<span class="world_entry_form_token_counter">0</span>
)
<span>(Tokens:&nbsp; <span class="world_entry_form_token_counter" data-first-run="true">counting...</span>)
</span>
</span>
</small>
@ -4356,4 +4354,4 @@
</script>
</body>
</html>
</html>

View File

@ -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;
}

View File

@ -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();

View File

@ -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);