Repository: typeorm/typeorm
File: src/query-builder/SelectQueryBuilder.ts (TypeScript)

Code before:

    private lazyCount(entitiesAndRaw: { entities: Entity[]; raw: any[] }) {
        const hasLimit =
            this.expressionMap.limit !== undefined &&
            this.expressionMap.limit !== null
        if (this.expressionMap.joinAttributes.length > 0 && hasLimit) {
            return undefined
        }

        let maxResults = undefined

        const hasTake =
            this.expressionMap.take !== undefined &&
            this.expressionMap.take !== null
        if (hasTake) {
            maxResults = this.expressionMap.take
        }

        if (hasLimit) {
            // limit overrides take when no join is defined
            maxResults = this.expressionMap.limit
        }

        if (
            maxResults !== undefined &&
            entitiesAndRaw.entities.length == maxResults
        ) {
            return undefined
        }

        let previousResults = 0
        if (
            this.expressionMap.skip !== undefined &&
            this.expressionMap.skip !== null &&
            this.expressionMap.skip > 0
        ) {
            previousResults = this.expressionMap.skip
        }

        if (
            this.expressionMap.offset !== undefined &&
            this.expressionMap.offset !== null &&
            this.expressionMap.offset > 0
        ) {
            // offset overrides skip when no join is defined
            previousResults = this.expressionMap.offset
        }

        return entitiesAndRaw.entities.length + previousResults
    }


Review comment (suggestion):
```suggestion
            entitiesAndRaw.entities.length === maxResults
```

Code after:
        raw: any[]
    }): number | undefined {
        const hasLimit =
            this.expressionMap.limit !== undefined &&
            this.expressionMap.limit !== null
        if (this.expressionMap.joinAttributes.length > 0 && hasLimit) {
            return undefined
        }

        const hasTake =
            this.expressionMap.take !== undefined &&
            this.expressionMap.take !== null

        // limit overrides take when no join is defined
        const maxResults = hasLimit
            ? this.expressionMap.limit
            : hasTake
            ? this.expressionMap.take
            : undefined

        if (
            maxResults !== undefined &&
            entitiesAndRaw.entities.length === maxResults
        ) {
            // stop here when the result set contains the max number of rows; we need to execute a full count
            return undefined
        }

        const hasSkip =
            this.expressionMap.skip !== undefined &&
            this.expressionMap.skip !== null &&
            this.expressionMap.skip > 0
        const hasOffset =
            this.expressionMap.offset !== undefined &&
            this.expressionMap.offset !== null &&
            this.expressionMap.offset > 0

        // offset overrides skip when no join is defined
        const previousResults: number = hasOffset
            ? this.expressionMap.offset!
            : hasSkip
            ? this.expressionMap.skip!
            : 0

        return entitiesAndRaw.entities.length + previousResults
    }

    /**
     * Executes built SQL query and returns raw data stream.
     */
    async stream(): Promise<ReadStream> {