Repository: typeorm/typeorm
File: src/persistence/SubjectDatabaseEntityLoader.ts (TypeScript)

Code before:
                    "mongodb"
                ) {
                    const mongoRepo =
                        this.queryRunner.manager.getRepository<ObjectLiteral>(
                            subjectGroup.target,
                        ) as MongoRepository<ObjectLiteral>
                    entities = await mongoRepo.findByIds(allIds, findOptions)
                } else {
                    entities = await this.queryRunner.manager
                        .getRepository<ObjectLiteral>(subjectGroup.target)
                        .createQueryBuilder()
                        .setFindOptions(findOptions)
                        .whereInIds(allIds)
                        .getMany()
                }

                // now when we have entities we need to find subject of each entity
                // and insert that entity into database entity of the found subjects
                entities.forEach((entity) => {
                    const subjects = this.findByPersistEntityLike(
                        subjectGroup.target,
                        entity,
                    )
                    subjects.forEach((subject) => {
                        subject.databaseEntity = entity
                        if (!subject.identifier)
                            subject.identifier =
                                subject.metadata.hasAllPrimaryKeys(entity)
                                    ? subject.metadata.getEntityIdMap(entity)
                                    : undefined
                    })
                })

                // this way we tell what subjects we tried to load database entities of
                for (const subject of allSubjects) {
                    subject.databaseEntityLoaded = true
                }
            },
        )

        await Promise.all(promises)
    }

    // ---------------------------------------------------------------------
    // Protected Methods
    // ---------------------------------------------------------------------

    /**
     * Finds subjects where entity like given subject's entity.
     * Comparison made by entity id.
     * Multiple subjects may be returned if duplicates are present in the subject array.

Review comment (suggestion):
It seems to be a dead code. Without identifier subject can't be matched to any entity. All subjects in `allSubjects` array has identifiers, we check it while creating the array.

Code after:
                    this.queryRunner.connection.driver.options.type ===
                    "mongodb"
                ) {
                    const mongoRepo =
                        this.queryRunner.manager.getRepository<ObjectLiteral>(
                            subjectGroup.target,
                        ) as MongoRepository<ObjectLiteral>
                    entities = await mongoRepo.findByIds(allIds, findOptions)
                } else {
                    entities = await this.queryRunner.manager
                        .getRepository<ObjectLiteral>(subjectGroup.target)
                        .createQueryBuilder()
                        .setFindOptions(findOptions)
                        .whereInIds(allIds)
                        .getMany()
                }

                // Now when we have entities we need to find subject of each entity
                // and insert that entity into database entity of the found subjects.
                // A single entity can be applied to many subjects as there might be duplicates.
                // This will likely result in the same row being updated multiple times during a transaction.
                entities.forEach((entity) => {
                    const entityId =
                        allSubjects[0].metadata.getEntityIdMap(entity)
                    allSubjects.forEach((subject) => {
                        if (subject.databaseEntity) return
                        if (OrmUtils.compareIds(subject.identifier, entityId))
                            subject.databaseEntity = entity
                    })
                })

                // this way we tell what subjects we tried to load database entities of
                for (const subject of allSubjects) {
                    subject.databaseEntityLoaded = true
                }
            },
        )

        await Promise.all(promises)
    }

    // ---------------------------------------------------------------------
    // Protected Methods
    // ---------------------------------------------------------------------

    /**
     * Groups given Subject objects into groups separated by entity targets.
     */
    protected groupByEntityTargets(): {
        target: Function | string
        subjects: Subject[]