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

Code before:
                // means we created our own query runner
                await queryRunner.release()
        }
    }

    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
        }

Review comment (suggestion):
Simpler with a ternary:

```suggestion
        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
```

Code after:
    }

    private lazyCount(entitiesAndRaw: {
        entities: Entity[]
        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
    }