Merge pull request #2543 from LenAnderson/streaming-performance

Remove DOM queries and jQuery during streaming
This commit is contained in:
Cohee 2024-07-22 19:24:41 +03:00 committed by GitHub
commit 67f83250cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 5 deletions

View File

@ -2797,6 +2797,10 @@ class StreamingProcessor {
constructor(type, force_name2, timeStarted, messageAlreadyGenerated) { constructor(type, force_name2, timeStarted, messageAlreadyGenerated) {
this.result = ''; this.result = '';
this.messageId = -1; this.messageId = -1;
this.messageDom = null;
this.messageTextDom = null;
this.messageTimerDom = null;
this.sendTextarea = document.querySelector('#send_textarea');
this.type = type; this.type = type;
this.force_name2 = force_name2; this.force_name2 = force_name2;
this.isStopped = false; this.isStopped = false;
@ -2833,11 +2837,15 @@ class StreamingProcessor {
let messageId = -1; let messageId = -1;
if (this.type == 'impersonate') { if (this.type == 'impersonate') {
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true })); this.sendTextarea.value = '';
this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true }));
} }
else { else {
await saveReply(this.type, text, true); await saveReply(this.type, text, true);
messageId = chat.length - 1; messageId = chat.length - 1;
this.messageDom = document.querySelector(`#chat .mes[mesid="${messageId}"]`);
this.messageTextDom = this.messageDom.querySelector('.mes_text');
this.messageTimerDom = this.messageDom.querySelector('.mes_timer');
this.showMessageButtons(messageId); this.showMessageButtons(messageId);
} }
@ -2869,7 +2877,8 @@ class StreamingProcessor {
} }
if (isImpersonate) { if (isImpersonate) {
$('#send_textarea').val(processedText)[0].dispatchEvent(new Event('input', { bubbles: true })); this.sendTextarea.value = processedText;
this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true }));
} }
else { else {
let currentTime = new Date(); let currentTime = new Date();
@ -2902,9 +2911,9 @@ class StreamingProcessor {
chat[messageId].is_user, chat[messageId].is_user,
messageId, messageId,
); );
const mesText = $(`#chat .mes[mesid="${messageId}"] .mes_text`); this.messageTextDom.innerHTML = formattedText;
mesText.html(formattedText); this.messageTimerDom.textContent = timePassed.timerValue;
$(`#chat .mes[mesid="${messageId}"] .mes_timer`).text(timePassed.timerValue).attr('title', timePassed.timerTitle); this.messageTimerDom.title = timePassed.timerTitle;
this.setFirstSwipe(messageId); this.setFirstSwipe(messageId);
} }