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 8658ad7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/metadata/EntityMetadata.ts
Expand Up @@ -746,6 +746,16 @@ 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" &&
typeof secondId.id === "string" &&
Object.keys(firstId).length === 1 &&
Object.keys(secondId).length === 1
) {
return firstId.id === secondId.id;
}

return OrmUtils.deepCompare(firstId, secondId);
}

Expand Down

0 comments on commit 8658ad7

Please sign in to comment.