From e1e0309c6d002a646eabe59b402e8e5750f83d64 Mon Sep 17 00:00:00 2001 From: Donkoko Date: Mon, 24 Jun 2024 18:32:59 +0300 Subject: [PATCH 1/2] changed links to 'new' inside dynamic select to open in new tab --- app/components/assets/form.tsx | 2 ++ app/components/location/location-select.tsx | 1 + 2 files changed, 3 insertions(+) diff --git a/app/components/assets/form.tsx b/app/components/assets/form.tsx index bdd08f860..6abf00f9b 100644 --- a/app/components/assets/form.tsx +++ b/app/components/assets/form.tsx @@ -261,6 +261,7 @@ export const AssetForm = ({ variant="link" icon="plus" className="w-full justify-start pt-4" + target="_blank" > Create new category @@ -319,6 +320,7 @@ export const AssetForm = ({ variant="link" icon="plus" className="w-full justify-start pt-4" + target="_blank" > Create new location diff --git a/app/components/location/location-select.tsx b/app/components/location/location-select.tsx index ef4309e4d..a80edd474 100644 --- a/app/components/location/location-select.tsx +++ b/app/components/location/location-select.tsx @@ -40,6 +40,7 @@ export const LocationSelect = () => { variant="link" icon="plus" className="w-full justify-start pt-4" + target="_blank" > Create new location From 0a9bedc5f361444d926adb80cddfa1b18f78593c Mon Sep 17 00:00:00 2001 From: Donkoko Date: Mon, 24 Jun 2024 19:15:37 +0300 Subject: [PATCH 2/2] testing approach with batching --- app/modules/asset/service.server.ts | 88 +++++++++++++++++------------ 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/app/modules/asset/service.server.ts b/app/modules/asset/service.server.ts index af6fbec6b..03932d0bb 100644 --- a/app/modules/asset/service.server.ts +++ b/app/modules/asset/service.server.ts @@ -1792,43 +1792,59 @@ export async function createAssetsFromContentImport({ userId, }); - for (let asset of data) { - const customFieldsValues: ShelfAssetCustomFieldValueType[] = - Object.entries(asset).reduce((res, [key, val]) => { - if (key.startsWith("cf:") && val) { - const { name } = getDefinitionFromCsvHeader(key); - if (customFields[name].id) { - res.push({ - id: customFields[name].id, - value: buildCustomFieldValue( - { raw: asset[key] }, - customFields[name] - ), - } as ShelfAssetCustomFieldValueType); - } + const BATCH_SIZE = 10; // Adjust based on your server's capacity + + for (let i = 0; i < data.length; i += BATCH_SIZE) { + const batch = data.slice(i, i + BATCH_SIZE); + await Promise.all( + batch.map(async (asset) => { + try { + // Your existing logic to process each asset + const customFieldsValues: ShelfAssetCustomFieldValueType[] = + Object.entries(asset).reduce((res, [key, val]) => { + if (key.startsWith("cf:") && val) { + const { name } = getDefinitionFromCsvHeader(key); + if (customFields[name].id) { + res.push({ + id: customFields[name].id, + value: buildCustomFieldValue( + { raw: asset[key] }, + customFields[name] + ), + } as ShelfAssetCustomFieldValueType); + } + } + return res; + }, [] as ShelfAssetCustomFieldValueType[]); + await createAsset({ + organizationId, + title: asset.title, + description: asset.description || "", + userId, + categoryId: asset.category ? categories[asset.category] : null, + locationId: asset.location + ? locations[asset.location] + : undefined, + custodian: asset.custodian + ? teamMembers[asset.custodian] + : undefined, + tags: + asset.tags.length > 0 + ? { + set: asset.tags + .filter((t) => tags[t]) + .map((t) => ({ id: tags[t] })), + } + : undefined, + valuation: asset.valuation ? +asset.valuation : null, + customFieldsValues, + }); + } catch (error) { + console.error("Error processing asset", error); + // Handle the error as needed } - return res; - }, [] as ShelfAssetCustomFieldValueType[]); - - await createAsset({ - organizationId, - title: asset.title, - description: asset.description || "", - userId, - categoryId: asset.category ? categories[asset.category] : null, - locationId: asset.location ? locations[asset.location] : undefined, - custodian: asset.custodian ? teamMembers[asset.custodian] : undefined, - tags: - asset.tags.length > 0 - ? { - set: asset.tags - .filter((t) => tags[t]) - .map((t) => ({ id: tags[t] })), - } - : undefined, - valuation: asset.valuation ? +asset.valuation : null, - customFieldsValues, - }); + }) + ); } } catch (cause) { throw new ShelfError({