Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a CoreData multithreading issue in LoggerStore.info() #293

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading