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); }