From 99bed3d0c0adfbdbc96c33e0e00176ea970a4101 Mon Sep 17 00:00:00 2001 From: Reto Kaiser Date: Sun, 26 Jan 2020 19:44:42 +0100 Subject: [PATCH] perf: Optimized version of EntityMetadata#compareIds() for the common case --- src/metadata/EntityMetadata.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/metadata/EntityMetadata.ts b/src/metadata/EntityMetadata.ts index 952c720e17a..040873bda05 100644 --- a/src/metadata/EntityMetadata.ts +++ b/src/metadata/EntityMetadata.ts @@ -746,6 +746,14 @@ export class EntityMetadata { if (firstId === undefined || firstId === null || secondId === undefined || secondId === null) return false; + // Optimized version for the common case + if ( + typeof firstId.id === "string" && Object.keys(firstId).length === 1 && + typeof secondId.id === "string" && Object.keys(secondId).length === 1 + ) { + return firstId.id === secondId.id; + } + return OrmUtils.deepCompare(firstId, secondId); }