Typeorm performance issues with many relations

Viewed 1787

I have the following query:

const foundAllOrders = await orderRepository.find({
  relations: ['inventoryItemType', 'inventoryItemType.quality',
    'inventory', 'inventory.proveDocuments',
    'inventory.proveDocuments.storage',
    'account',
    'inventory.labAttestationDocs',
    'inventory.labAttestationDocs.storage',
    'inventory.productPicture',
    'inventory.productPicture.storage',
    'inventory.inventoryItemSavedFields',
    'inventory.inventoryItemSavedFields.proveDocuments',
    'inventory.inventoryItemSavedFields.proveDocuments.storage',
    'orderSavedFields'],
});

Execution time is about 2sec.

Maybe anyone know the way to optimize it?

1 Answers

So. I just use now pagination + remove excessive fields from my request, and get only necessary data for UI. This solved the performance issue. Also added indexes.

Related