Skip to content

Commit 4d9d6de

Browse files
committed
fix: revert unsafe nullish coalescing conversions
- SelectQueryBuilder: rewrite cache enablement as ternary to preserve boolean OR semantics (false should fall through to per-query cache) - DriverUtils: normalize empty database string to undefined before ?? - RedisQueryResultCache: normalize empty identifier to undefined before ??
1 parent eea3dcd commit 4d9d6de

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎src/cache/RedisQueryResultCache.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export class RedisQueryResultCache implements QueryResultCache {
125125
options: QueryResultCacheOptions,
126126
queryRunner?: QueryRunner,
127127
): Promise<QueryResultCacheOptions | undefined> {
128-
const key = options.identifier ?? options.query
128+
const identifier =
129+
options.identifier === "" ? undefined : options.identifier
130+
const key = identifier ?? options.query
129131
if (!key) return undefined
130132

131133
const result = await this.client.get(key)
@@ -153,7 +155,9 @@ export class RedisQueryResultCache implements QueryResultCache {
153155
savedCache: QueryResultCacheOptions,
154156
queryRunner?: QueryRunner,
155157
): Promise<void> {
156-
const key = options.identifier ?? options.query
158+
const identifier =
159+
options.identifier === "" ? undefined : options.identifier
160+
const key = identifier ?? options.query
157161
if (!key) return
158162

159163
const value = JSON.stringify(options)

‎src/driver/DriverUtils.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ export class DriverUtils {
179179
if (afterBase && afterBase.indexOf("?") !== -1) {
180180
afterBase = afterBase.substring(0, afterBase.indexOf("?"))
181181
}
182+
// normalize empty string to undefined so downstream ?? works correctly
183+
if (afterBase === "") afterBase = undefined
182184

183185
const lastAtSign = base.lastIndexOf("@")
184186
const usernameAndPassword = base.substring(0, lastAtSign)
@@ -217,6 +219,8 @@ export class DriverUtils {
217219
secondSlash !== -1 ? preBase.substring(0, secondSlash) : preBase
218220
let afterBase =
219221
secondSlash !== -1 ? preBase.substring(secondSlash + 1) : undefined
222+
// normalize empty string to undefined so downstream ?? works correctly
223+
if (afterBase === "") afterBase = undefined
220224
let afterQuestionMark: string
221225
let host = undefined
222226
let port = undefined

‎src/query-builder/SelectQueryBuilder.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,12 +3854,9 @@ export class SelectQueryBuilder<Entity extends ObjectLiteral>
38543854
: {}
38553855
let savedQueryResultCacheOptions: QueryResultCacheOptions | undefined =
38563856
undefined
3857-
const isCachingEnabled =
3858-
// Caching is enabled globally and isn't disabled locally.
3859-
(cacheOptions.alwaysEnabled &&
3860-
this.expressionMap.cache !== false) ??
3861-
// ...or it's enabled locally explicitly.
3862-
this.expressionMap.cache === true
3857+
const isCachingEnabled = cacheOptions.alwaysEnabled
3858+
? this.expressionMap.cache !== false
3859+
: this.expressionMap.cache === true
38633860
let cacheError = false
38643861
if (this.dataSource.queryResultCache && isCachingEnabled) {
38653862
try {

0 commit comments

Comments
 (0)