Skip to content

Commit a2f93de

Browse files
committed
Improve nested list/object performance
Fix #628 Fix #877
1 parent 43b1704 commit a2f93de

22 files changed

Lines changed: 394 additions & 59 deletions

src/lib/components/contents/details/editor/copy-menu-items.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
import { entryDraft } from '$lib/services/contents/draft';
66
import { copyFromLocale } from '$lib/services/contents/draft/update/copy';
7+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
78
import { getLocaleLabel } from '$lib/services/contents/i18n';
89
import { translator } from '$lib/services/integrations/translators';
910
@@ -38,11 +39,11 @@
3839
const isMenuDisabled = async ({ sourceLanguage, targetLanguage }) =>
3940
!$entryDraft?.currentLocales[targetLanguage] ||
4041
!$entryDraft.currentLocales[sourceLanguage] ||
41-
(!!keyPath && !$state.snapshot($entryDraft.currentValues[sourceLanguage])[keyPath]) ||
42+
(!!keyPath && !getValueMapSnapshot($entryDraft, sourceLanguage)[keyPath]) ||
4243
(!translate &&
4344
!!keyPath &&
44-
$state.snapshot($entryDraft.currentValues[sourceLanguage])[keyPath] ===
45-
$state.snapshot($entryDraft.currentValues[targetLanguage])[keyPath]) ||
45+
getValueMapSnapshot($entryDraft, sourceLanguage)[keyPath] ===
46+
getValueMapSnapshot($entryDraft, targetLanguage)[keyPath]) ||
4647
(translate && !(await $translator?.availability({ sourceLanguage, targetLanguage })));
4748
</script>
4849

src/lib/components/contents/details/editor/field-editor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
resolveOriginalKeyPath,
2020
revertChanges,
2121
} from '$lib/services/contents/draft/update/revert';
22+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
2223
import {
2324
getCurrentValue,
2425
getFieldKind,
@@ -152,7 +153,7 @@
152153
const canCopy = $derived(!inEditorComponent && canTranslate && otherLocales.length);
153154
const canRevert = $derived(!inEditorComponent && !(canDuplicate && locale !== defaultLocale));
154155
const keyPathRegex = $derived(new RegExp(`^${escapeRegExp(keyPath)}\\.\\d+$`));
155-
const valueMap = $derived($state.snapshot($entryDraft?.[valueStoreKey][locale] ?? {}));
156+
const valueMap = $derived(getValueMapSnapshot($entryDraft, locale, valueStoreKey));
156157
const customFieldType = $derived(customFieldTypeRegistry.get(fieldType));
157158
const currentValue = $derived(
158159
getCurrentValue({

src/lib/components/contents/details/fields/code/code-editor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { getContext, untrack } from 'svelte';
1111
1212
import { entryDraft } from '$lib/services/contents/draft';
13+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
1314
1415
/**
1516
* @import { FieldEditorContext, FieldEditorProps } from '$lib/types/private';
@@ -48,7 +49,7 @@
4849
output_code_only: outputCodeOnly = false,
4950
keys: outputKeys = { code: 'code', lang: 'lang' },
5051
} = $derived(fieldConfig);
51-
const valueMap = $derived($state.snapshot($entryDraft?.[valueStoreKey][locale]) ?? {});
52+
const valueMap = $derived(getValueMapSnapshot($entryDraft, locale, valueStoreKey));
5253
const codeKeyPath = $derived(`${keyPath}.${outputKeys.code}`);
5354
const langKeyPath = $derived(`${keyPath}.${outputKeys.lang}`);
5455

src/lib/components/contents/details/fields/code/code-preview.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
-->
77
<script>
88
import { entryDraft } from '$lib/services/contents/draft';
9+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
910
1011
/**
1112
* @import { FieldEditorProps } from '$lib/types/private';
@@ -33,7 +34,7 @@
3334
output_code_only: outputCodeOnly = false,
3435
keys: outputKeys = { code: 'code', lang: 'lang' },
3536
} = $derived(fieldConfig);
36-
const valueMap = $derived($state.snapshot($entryDraft?.currentValues[locale]) ?? {});
37+
const valueMap = $derived(getValueMapSnapshot($entryDraft, locale));
3738
const codeKeyPath = $derived(`${keyPath}.${outputKeys.code}`);
3839
const langKeyPath = $derived(`${keyPath}.${outputKeys.lang}`);
3940
const code = $derived(outputCodeOnly ? currentValue : valueMap[codeKeyPath]);

src/lib/components/contents/details/fields/compute/compute-editor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { replaceTemplateTags } from '$lib/services/common/template';
1111
import { applyTransformations, parseTransformations } from '$lib/services/common/transformations';
1212
import { entryDraft } from '$lib/services/contents/draft';
13+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
1314
import { getFieldDisplayValue } from '$lib/services/contents/entry/fields';
1415
import { getListFormatter } from '$lib/services/contents/i18n';
1516
import { isNumeric } from '$lib/services/utils/number';
@@ -46,7 +47,7 @@
4647
const isIndexFile = $derived($entryDraft?.isIndexFile ?? false);
4748
const collectionName = $derived($entryDraft?.collectionName ?? '');
4849
const fileName = $derived($entryDraft?.fileName);
49-
const valueMap = $derived($state.snapshot($entryDraft?.[valueStoreKey][locale]) ?? {});
50+
const valueMap = $derived(getValueMapSnapshot($entryDraft, locale, valueStoreKey));
5051
const listFormatter = $derived(getListFormatter(locale));
5152
5253
/**

src/lib/components/contents/details/fields/file/file-editor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import FileEditorItem from '$lib/components/contents/details/fields/file/file-editor-item.svelte';
1919
import UploadButton from '$lib/components/contents/details/fields/file/upload-button.svelte';
2020
import { entryDraft } from '$lib/services/contents/draft';
21+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
2122
import { checkDuplicates } from '$lib/services/contents/fields/file/duplicates.svelte';
2223
import {
2324
getAssetLibraryFolderMap,
@@ -287,7 +288,7 @@
287288
return;
288289
}
289290
290-
const valueMap = $state.snapshot($entryDraft[valueStoreKey][locale]);
291+
const valueMap = getValueMapSnapshot($entryDraft, locale, valueStoreKey);
291292
/** @type {string[]} */
292293
const updatedValue = [];
293294

src/lib/components/contents/details/fields/key-value/key-value-editor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
import ValidationError from '$lib/components/contents/details/editor/validation-error.svelte';
1414
import { entryDraft } from '$lib/services/contents/draft';
15+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
1516
import {
1617
getPairs,
1718
savePairs,
@@ -152,7 +153,7 @@
152153
};
153154
154155
$effect(() => {
155-
void [$state.snapshot($entryDraft?.[valueStoreKey][locale])];
156+
void [getValueMapSnapshot($entryDraft, locale, valueStoreKey)];
156157
157158
untrack(() => {
158159
updatePairs();

src/lib/components/contents/details/fields/key-value/key-value-preview.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { untrack } from 'svelte';
1111
1212
import { entryDraft } from '$lib/services/contents/draft';
13+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
1314
import { getPairs } from '$lib/services/contents/fields/key-value/helpers';
1415
1516
/**
@@ -58,7 +59,7 @@
5859
5960
$effect(() => {
6061
if ($entryDraft) {
61-
void [$state.snapshot($entryDraft.currentValues[locale])];
62+
void [getValueMapSnapshot($entryDraft, locale)];
6263
6364
untrack(() => {
6465
updatePairs();

src/lib/components/contents/details/fields/list/list-editor-complex.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import { entryDraft } from '$lib/services/contents/draft';
3333
import { getDefaultValues } from '$lib/services/contents/draft/defaults';
3434
import { updateListField } from '$lib/services/contents/draft/update/list';
35+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
3536
import {
3637
getInitialExpanderState,
3738
syncExpanderStates,
@@ -103,7 +104,7 @@
103104
const fileName = $derived($entryDraft?.fileName);
104105
const { defaultLocale } = $derived((collectionFile ?? collection)?._i18n ?? DEFAULT_I18N_CONFIG);
105106
const isDuplicateField = $derived(locale !== defaultLocale && i18n === 'duplicate');
106-
const valueMap = $derived($state.snapshot($entryDraft?.[valueStoreKey][locale]) ?? {});
107+
const valueMap = $derived(getValueMapSnapshot($entryDraft, locale, valueStoreKey));
107108
const parentExpandedKeyPath = $derived(`${keyPath}#`);
108109
const parentExpanded = $derived($entryDraft?.expanderStates?._[parentExpandedKeyPath] ?? true);
109110
/** @type {Record<string, any>[]} */

src/lib/components/contents/details/fields/list/list-preview-complex.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import Subsection from '$lib/components/contents/details/fields/object/subsection.svelte';
1414
import FieldPreview from '$lib/components/contents/details/preview/field-preview.svelte';
1515
import { entryDraft } from '$lib/services/contents/draft';
16+
import { getValueMapSnapshot } from '$lib/services/contents/draft/value-map.svelte';
1617
import { getListFieldInfo } from '$lib/services/contents/fields/list/helpers';
1718
1819
/**
@@ -50,7 +51,7 @@
5051
const items = $derived(
5152
unflatten(
5253
Object.fromEntries(
53-
Object.entries($state.snapshot($entryDraft?.currentValues[locale]) ?? {})
54+
Object.entries(getValueMapSnapshot($entryDraft, locale))
5455
.filter(([_keyPath]) => keyPathRegex.test(_keyPath))
5556
.map(([_keyPath, value]) => [`${fieldName}${_keyPath.slice(keyPath.length)}`, value]),
5657
),

0 commit comments

Comments
 (0)