Skip to content

Commit 117559e

Browse files
committed
perf: extend fast-deep-equal to remaining call sites
1 parent 606e51b commit 117559e

5 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import { get, type Unsubscriber, type Writable } from 'svelte/store';
1414
import type { i18n as i18nType } from 'i18next';
1515
import { WEBUI_BASE_URL } from '$lib/constants';
16+
import equal from 'fast-deep-equal';
1617
1718
import {
1819
chatId,
@@ -277,7 +278,7 @@
277278
};
278279
279280
let oldSelectedModelIds = [''];
280-
$: if (JSON.stringify(selectedModelIds) !== JSON.stringify(oldSelectedModelIds)) {
281+
$: if (!equal(selectedModelIds, oldSelectedModelIds)) {
281282
onSelectedModelIdsChange();
282283
}
283284
@@ -674,7 +675,7 @@
674675
if (
675676
$selectedFolder &&
676677
selectedModels.filter((modelId) => modelId !== '').length > 0 &&
677-
JSON.stringify($selectedFolder?.data?.model_ids) !== JSON.stringify(selectedModels)
678+
!equal($selectedFolder?.data?.model_ids, selectedModels)
678679
) {
679680
const res = await updateFolderById(localStorage.token, $selectedFolder.id, {
680681
data: {
@@ -758,7 +759,7 @@
758759
await tick();
759760
if (
760761
folder?.data?.model_ids &&
761-
JSON.stringify(selectedModels) !== JSON.stringify(folder.data.model_ids)
762+
!equal(selectedModels, folder.data.model_ids)
762763
) {
763764
selectedModels = folder.data.model_ids;
764765
@@ -1851,7 +1852,7 @@
18511852
chatFiles = chatFiles.filter(
18521853
// Remove duplicates
18531854
(item, index, array) =>
1854-
array.findIndex((i) => JSON.stringify(i) === JSON.stringify(item)) === index
1855+
array.findIndex((i) => equal(i, item)) === index
18551856
);
18561857
18571858
// Create user message
@@ -1895,7 +1896,7 @@
18951896
$models.map((m) => m.id).includes(modelId) ? modelId : ''
18961897
);
18971898
1898-
if (JSON.stringify(selectedModels) !== JSON.stringify(_selectedModels)) {
1899+
if (!equal(selectedModels, _selectedModels)) {
18991900
selectedModels = _selectedModels;
19001901
}
19011902
@@ -2192,7 +2193,7 @@
21922193
// Remove duplicates
21932194
files = files.filter(
21942195
(item, index, array) =>
2195-
array.findIndex((i) => JSON.stringify(i) === JSON.stringify(item)) === index
2196+
array.findIndex((i) => equal(i, item)) === index
21962197
);
21972198
21982199
scrollToBottom();

src/lib/components/chat/Messages/CodeBlock.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
} from '$lib/utils';
1616
1717
import 'highlight.js/styles/github-dark.min.css';
18+
import equal from 'fast-deep-equal';
1819
1920
import CodeEditor from '$lib/components/common/CodeEditor.svelte';
2021
import SvgPanZoom from '$lib/components/common/SVGPanZoom.svelte';
@@ -391,7 +392,7 @@
391392
$: if (token) {
392393
if (token.text !== _token?.text || token.raw !== _token?.raw) {
393394
_token = token;
394-
} else if (JSON.stringify(token) !== JSON.stringify(_token)) {
395+
} else if (!equal(token, _token)) {
395396
_token = token;
396397
}
397398
}

src/lib/components/chat/ModelSelector.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Tooltip from '../common/Tooltip.svelte';
77
88
import { updateUserSettings } from '$lib/apis/users';
9+
import equal from 'fast-deep-equal';
910
const i18n = getContext('i18n');
1011
1112
export let selectedModels = [''];
@@ -43,7 +44,7 @@
4344
$models.map((m) => m.id).includes(model) ? model : ''
4445
);
4546
46-
if (JSON.stringify(_selectedModels) !== JSON.stringify(selectedModels)) {
47+
if (!equal(_selectedModels, selectedModels)) {
4748
selectedModels = _selectedModels;
4849
}
4950
}

src/lib/components/common/RichTextInput.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { marked } from 'marked';
33
import DOMPurify from 'dompurify';
4+
import equal from 'fast-deep-equal';
45
56
marked.use({
67
breaks: true,
@@ -1246,7 +1247,7 @@
12461247
}
12471248
12481249
if (json) {
1249-
if (JSON.stringify(value) !== JSON.stringify(jsonValue)) {
1250+
if (!equal(value, jsonValue)) {
12501251
editor.commands.setContent(value);
12511252
selectTemplate();
12521253
}

src/lib/components/notes/NoteEditor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
import { marked } from 'marked';
1010
import { toast } from 'svelte-sonner';
11+
import equal from 'fast-deep-equal';
1112
1213
import { goto } from '$app/navigation';
1314
@@ -226,7 +227,7 @@
226227
}
227228
228229
function areContentsEqual(a, b) {
229-
return JSON.stringify(a) === JSON.stringify(b);
230+
return equal(a, b);
230231
}
231232
232233
function insertNoteVersion(note) {

0 commit comments

Comments
 (0)