Skip to content

Commit

Permalink
Merge pull request #293 from ejensen/core-data-threading-issue
Browse files Browse the repository at this point in the history
Fix a CoreData multithreading issue in `LoggerStore.info()`
  • Loading branch information
kean authored Sep 19, 2024
2 parents 29c1ad5 + 3f9378f commit 2380f56
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/Pulse/LoggerStore/LoggerStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ extension LoggerStore {
}

private func reduceBlobStoreSize() throws {
var currentSize = try getBlobsSize()
var currentSize = try getBlobsSize(in: backgroundContext)

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

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

let description = NSExpressionDescription()
Expand All @@ -1162,7 +1162,7 @@ extension LoggerStore {
request.propertiesToFetch = [description]
request.resultType = .dictionaryResultType

let result = try backgroundContext.fetch(request) as? [[String: Any]]
let result = try context.fetch(request) as? [[String: Any]]
return (result?.first?[description.name] as? Int64) ?? 0
}
}
Expand Down Expand Up @@ -1196,8 +1196,8 @@ extension LoggerStore {
taskCount: taskCount,
blobCount: blobCount,
totalStoreSize: try storeURL.directoryTotalSize(),
blobsSize: try getBlobsSize(),
blobsDecompressedSize: try getBlobsSize(isDecompressed: true),
blobsSize: try getBlobsSize(in: context),
blobsDecompressedSize: try getBlobsSize(in: context, isDecompressed: true),
appInfo: .current,
deviceInfo: deviceInfo
)
Expand Down

0 comments on commit 2380f56

Please sign in to comment.