mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-10 03:27:57 +00:00
perf: use structuredClone and fast-path comparison in UserMessage (#22098)
Same optimization as the merged ResponseMessage PR: replace JSON.parse(JSON.stringify()) with structuredClone and add an O(1) fast-path check on content before falling back to full JSON.stringify comparison.
This commit is contained in:
parent
387225eb8b
commit
597883a179
1 changed files with 8 additions and 3 deletions
|
|
@ -52,10 +52,15 @@
|
|||
let messageEditTextAreaElement: HTMLTextAreaElement;
|
||||
let editScrollContainer: HTMLDivElement;
|
||||
|
||||
let message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
||||
let message = structuredClone(history.messages[messageId]);
|
||||
$: if (history.messages) {
|
||||
if (JSON.stringify(message) !== JSON.stringify(history.messages[messageId])) {
|
||||
message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
||||
const source = history.messages[messageId];
|
||||
if (source) {
|
||||
if (message.content !== source.content) {
|
||||
message = structuredClone(source);
|
||||
} else if (JSON.stringify(message) !== JSON.stringify(source)) {
|
||||
message = structuredClone(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue