Skip to content

Commit 2380f56

Browse files
authored
Merge pull request #293 from ejensen/core-data-threading-issue
Fix a CoreData multithreading issue in `LoggerStore.info()`
2 parents 29c1ad5 + 3f9378f commit 2380f56

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sources/Pulse/LoggerStore/LoggerStore.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ extension LoggerStore {
11221122
}
11231123

11241124
private func reduceBlobStoreSize() throws {
1125-
var currentSize = try getBlobsSize()
1125+
var currentSize = try getBlobsSize(in: backgroundContext)
11261126

11271127
guard currentSize > configuration.blobSizeLimit else {
11281128
return // All good, no need to remove anything
@@ -1147,7 +1147,7 @@ extension LoggerStore {
11471147
}
11481148
}
11491149

1150-
private func getBlobsSize(isDecompressed: Bool = false) throws -> Int64 {
1150+
private func getBlobsSize(in context: NSManagedObjectContext, isDecompressed: Bool = false) throws -> Int64 {
11511151
let request = LoggerBlobHandleEntity.fetchRequest()
11521152

11531153
let description = NSExpressionDescription()
@@ -1162,7 +1162,7 @@ extension LoggerStore {
11621162
request.propertiesToFetch = [description]
11631163
request.resultType = .dictionaryResultType
11641164

1165-
let result = try backgroundContext.fetch(request) as? [[String: Any]]
1165+
let result = try context.fetch(request) as? [[String: Any]]
11661166
return (result?.first?[description.name] as? Int64) ?? 0
11671167
}
11681168
}
@@ -1196,8 +1196,8 @@ extension LoggerStore {
11961196
taskCount: taskCount,
11971197
blobCount: blobCount,
11981198
totalStoreSize: try storeURL.directoryTotalSize(),
1199-
blobsSize: try getBlobsSize(),
1200-
blobsDecompressedSize: try getBlobsSize(isDecompressed: true),
1199+
blobsSize: try getBlobsSize(in: context),
1200+
blobsDecompressedSize: try getBlobsSize(in: context, isDecompressed: true),
12011201
appInfo: .current,
12021202
deviceInfo: deviceInfo
12031203
)

0 commit comments

Comments
 (0)