Skip to content

Commit 68e7801

Browse files
Merge pull request #578 from OneSila/development
Update shein schema import performance
2 parents de4b072 + 1017540 commit 68e7801

File tree

5 files changed

+42
-43
lines changed

5 files changed

+42
-43
lines changed

src/core/integrations/integrations/integrations-show/containers/document-types/containers/remote-document-types/components/categories-lists/SheinDocumentTypeCategoriesList.vue

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { normalizeCategoryNode, type SheinCategoryNode } from '../../../../../..
1313
1414
type CategoryId = string | number;
1515
interface SheinCategorySelectionNode extends SheinCategoryNode {
16+
fullPath?: string | null;
1617
parentRemoteId?: string | null;
1718
}
1819
@@ -102,6 +103,7 @@ const emptyMessage = computed(() =>
102103
103104
const normalizeSheinNode = (node: any): SheinCategorySelectionNode => ({
104105
...normalizeCategoryNode(node),
106+
fullPath: node?.fullPath ?? null,
105107
parentRemoteId: node?.parentRemoteId ?? node?.parent?.remoteId ?? null,
106108
});
107109
@@ -159,32 +161,6 @@ const fetchCategoryByRemoteId = async (remoteId: string): Promise<SheinCategoryS
159161
}
160162
};
161163
162-
const buildPathFromNode = async (node: SheinCategorySelectionNode): Promise<string> => {
163-
const names: string[] = [];
164-
if (node.name) {
165-
names.unshift(node.name);
166-
}
167-
168-
let parentRemoteId = node.parentRemoteId ? String(node.parentRemoteId) : null;
169-
const visited = new Set<string>([node.remoteId]);
170-
let guard = 0;
171-
172-
while (parentRemoteId && guard < 30 && !visited.has(parentRemoteId)) {
173-
visited.add(parentRemoteId);
174-
const parentNode = await fetchCategoryByRemoteId(parentRemoteId);
175-
if (!parentNode) {
176-
break;
177-
}
178-
if (parentNode.name) {
179-
names.unshift(parentNode.name);
180-
}
181-
parentRemoteId = parentNode.parentRemoteId ? String(parentNode.parentRemoteId) : null;
182-
guard += 1;
183-
}
184-
185-
return names.join(' > ') || node.name || node.remoteId;
186-
};
187-
188164
const decodeCategories = async () => {
189165
const requestId = ++decodeRequestId;
190166
const ids = Array.from(new Set(remoteIds.value));
@@ -234,18 +210,14 @@ const decodeCategories = async () => {
234210
return;
235211
}
236212
mapped[node.remoteId] = node;
213+
pathMap[node.remoteId] = node.fullPath || node.name || node.remoteId;
237214
unresolvedIds.delete(node.remoteId);
238215
nodeCache.value = {
239216
...nodeCache.value,
240217
[node.remoteId]: node,
241218
};
242219
});
243220
}
244-
245-
for (const remoteId of Object.keys(mapped)) {
246-
const path = await buildPathFromNode(mapped[remoteId]);
247-
pathMap[remoteId] = path;
248-
}
249221
} catch (error) {
250222
displayApolloError(error);
251223
} finally {
@@ -274,7 +246,7 @@ const formatPath = (node: SheinCategorySelectionNode | null, remoteId: string):
274246
if (!node) {
275247
return remoteId;
276248
}
277-
return decodedPaths.value[remoteId] || node.name || remoteId;
249+
return decodedPaths.value[remoteId] || node.fullPath || node.name || remoteId;
278250
};
279251
280252
const addCategory = (node: SheinCategorySelectionNode, path: string) => {
@@ -352,7 +324,7 @@ const setManualCategory = async () => {
352324
return;
353325
}
354326
355-
const path = await buildPathFromNode(node);
327+
const path = node.fullPath || node.name || node.remoteId;
356328
addCategory(node, path);
357329
manualCategoryInput.value = '';
358330
resetSelectionPreview();

src/core/integrations/integrations/integrations-show/containers/document-types/containers/remote-document-types/configs.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ export const remoteDocumentTypesListingConfigConstructor = (
3232
): ListingConfig => ({
3333
headers: [
3434
t('shared.labels.name'),
35-
t('integrations.show.documentTypes.labels.translatedName'),
3635
t('integrations.show.documentTypes.labels.localInstance'),
3736
],
3837
fields: [
39-
{ name: 'name', type: FieldType.Text },
40-
{ name: 'translatedName', type: FieldType.Text },
38+
{ name: 'effectiveName', type: FieldType.Text },
4139
{
4240
name: 'localInstance',
4341
type: FieldType.NestedText,

src/core/products/products/product-show/containers/tabs/variations/containers/variations-images-bulk-edit/VariationsImagesBulkEdit.vue

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,34 @@ const closePlaceholder = () => {
541541
542542
const normalizeTextValue = (value?: string | null) => (value ?? '').trim();
543543
544+
const getDedupedImagesForSave = (row: VariationRow) => {
545+
const mediaMap = new Map<string, { slot: VariationImageSlot; sortOrder: number; isMainImage: boolean }>();
546+
547+
row.images.forEach((slot, index) => {
548+
if (!slot?.mediaId) {
549+
return;
550+
}
551+
552+
const existing = mediaMap.get(slot.mediaId);
553+
if (!existing) {
554+
mediaMap.set(slot.mediaId, {
555+
slot,
556+
sortOrder: index,
557+
isMainImage: !!slot.isMainImage,
558+
});
559+
return;
560+
}
561+
562+
existing.sortOrder = Math.min(existing.sortOrder, index);
563+
existing.isMainImage = existing.isMainImage || !!slot.isMainImage;
564+
if (!existing.slot.id && slot.id) {
565+
existing.slot = slot;
566+
}
567+
});
568+
569+
return Array.from(mediaMap.values()).sort((a, b) => a.sortOrder - b.sortOrder);
570+
};
571+
544572
const applyEditFormFromSlot = (slot: VariationImageSlot) => {
545573
syncingEditForm.value = true;
546574
editTitle.value = slot.title ?? '';
@@ -934,8 +962,9 @@ const save = async () => {
934962
variations.value.forEach((row) => {
935963
const original = originalMap.get(row.variation.id);
936964
const currentIds = new Set<string>();
965+
const dedupedImages = getDedupedImagesForSave(row);
937966
938-
row.images.forEach((slot, index) => {
967+
dedupedImages.forEach(({ slot, sortOrder, isMainImage }) => {
939968
if (!slot || !slot.mediaId) {
940969
return;
941970
}
@@ -951,17 +980,17 @@ const save = async () => {
951980
toCreate.push({
952981
productId: row.variation.id,
953982
mediaId: slot.mediaId,
954-
sortOrder: index,
955-
isMainImage: !!slot.isMainImage,
983+
sortOrder,
984+
isMainImage,
956985
});
957986
return;
958987
}
959988
currentIds.add(slot.id);
960989
const originalSlot = original?.images.find((item) => item?.id === slot.id) ?? null;
961990
const originalSort = originalSlot?.sortOrder ?? null;
962991
const originalMain = originalSlot?.isMainImage ?? false;
963-
if (originalSort !== index || originalMain !== slot.isMainImage) {
964-
toUpdate.push({ id: slot.id, sortOrder: index, isMainImage: !!slot.isMainImage });
992+
if (originalSort !== sortOrder || originalMain !== isMainImage) {
993+
toUpdate.push({ id: slot.id, sortOrder, isMainImage });
965994
}
966995
});
967996

src/shared/api/queries/salesChannels.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,8 +1942,7 @@ export const remoteDocumentTypesQuery = gql`
19421942
edges {
19431943
node {
19441944
id
1945-
name
1946-
translatedName
1945+
effectiveName
19471946
localInstance {
19481947
id
19491948
name

src/shared/api/queries/sheinCategories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const sheinCategoriesQuery = gql`
2121
node {
2222
remoteId
2323
name
24+
fullPath
2425
parentRemoteId
2526
isLeaf
2627
productTypeRemoteId

0 commit comments

Comments
 (0)