Skip to content

Commit

Permalink
perf: Optimized version of EntityMetadata#compareIds() for the common…
Browse files Browse the repository at this point in the history
… case
  • Loading branch information
njam committed Jan 26, 2020
1 parent 6c6bde7 commit 99bed3d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/metadata/EntityMetadata.ts
Expand Up @@ -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);
}

Expand Down

0 comments on commit 99bed3d

Please sign in to comment.