From b0982b691c1dee4b0e48acd0682b6d2b52519f0c Mon Sep 17 00:00:00 2001 From: Redm4x <2829180+Redm4x@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:17:47 -0500 Subject: [PATCH] Use bulk create for gpus&cpus --- .../src/providers/providerStatusProvider.ts | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/indexer/src/providers/providerStatusProvider.ts b/indexer/src/providers/providerStatusProvider.ts index 8c3bad44f..a6b9ccccd 100644 --- a/indexer/src/providers/providerStatusProvider.ts +++ b/indexer/src/providers/providerStatusProvider.ts @@ -164,31 +164,27 @@ async function saveProviderStatus( { transaction: t } ); - for (const cpuInfo of node.cpus) { - await ProviderSnapshotNodeCPU.create( - { - snapshotNodeId: providerSnapshotNode.id, - vendor: cpuInfo.vendor, - model: cpuInfo.model, - vcores: cpuInfo.vcores - }, - { transaction: t } - ); - } + await ProviderSnapshotNodeCPU.bulkCreate( + node.cpus.map((cpuInfo) => ({ + snapshotNodeId: providerSnapshotNode.id, + vendor: cpuInfo.vendor, + model: cpuInfo.model, + vcores: cpuInfo.vcores + })), + { transaction: t } + ); - for (const gpuInfo of node.gpus) { - await ProviderSnapshotNodeGPU.create( - { - snapshotNodeId: providerSnapshotNode.id, - vendor: gpuInfo.vendor, - name: gpuInfo.name, - modelId: gpuInfo.modelId, - interface: gpuInfo.interface, - memorySize: gpuInfo.memorySize // TODO: Change type to bytes? - }, - { transaction: t } - ); - } + await ProviderSnapshotNodeGPU.bulkCreate( + node.gpus.map((gpuInfo) => ({ + snapshotNodeId: providerSnapshotNode.id, + vendor: gpuInfo.vendor, + name: gpuInfo.name, + modelId: gpuInfo.modelId, + interface: gpuInfo.interface, + memorySize: gpuInfo.memorySize // TODO: Change type to bytes? + })), + { transaction: t } + ); } } });