Skip to content

Commit f1ab628

Browse files
committed
fix: drop unneded extra variable and also capture calculated size in warning
1 parent 006ce40 commit f1ab628

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/run/storage/request-scoped-in-memory-cache.cts

+3-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ const estimateBlobKnownTypeSize = (
6565
}
6666

6767
const estimateBlobSize = (valueToStore: BlobType | null | Promise<unknown>): PositiveNumber => {
68-
let knownTypeFailed = false
6968
let estimatedKnownTypeSize: number | undefined
7069
let estimateBlobKnownTypeSizeError: unknown
7170
try {
@@ -74,21 +73,21 @@ const estimateBlobSize = (valueToStore: BlobType | null | Promise<unknown>): Pos
7473
return estimatedKnownTypeSize
7574
}
7675
} catch (error) {
77-
knownTypeFailed = true
7876
estimateBlobKnownTypeSizeError = error
7977
}
8078

8179
// fallback for not known kinds or known kinds that did fail to calculate positive size
80+
const calculatedSize = JSON.stringify(valueToStore).length
81+
8282
// we should also monitor cases when fallback is used because it's not the most efficient way to calculate/estimate size
8383
// and might indicate need to make adjustments or additions to the size calculation
8484
recordWarning(
8585
new Error(
86-
`Blob size calculation did fallback to JSON.stringify. KnownTypeFailed: ${knownTypeFailed}, EstimatedKnownTypeSize: ${estimatedKnownTypeSize}, ValueToStore: ${JSON.stringify(valueToStore)}`,
86+
`Blob size calculation did fallback to JSON.stringify. EstimatedKnownTypeSize: ${estimatedKnownTypeSize}, CalculatedSize: ${calculatedSize}, ValueToStore: ${JSON.stringify(valueToStore)}`,
8787
estimateBlobKnownTypeSizeError ? { cause: estimateBlobKnownTypeSizeError } : undefined,
8888
),
8989
)
9090

91-
const calculatedSize = JSON.stringify(valueToStore).length
9291
return isPositiveNumber(calculatedSize) ? calculatedSize : BASE_BLOB_SIZE
9392
}
9493

0 commit comments

Comments
 (0)