Skip to content

Commit 50f9039

Browse files
committed
Track data usage in UploadManager
Records bytes transferred during custom episode uploads.
1 parent 19ef517 commit 50f9039

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Modules/Server/Sources/PocketCastsServer/Public/Upload/UploadManager+URLSessionDelegate.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ extension UploadManager: URLSessionDelegate, URLSessionDataDelegate {
99
// things smaller than 150kb are suspect, probably text, xml or html error pages
1010
private static let suspectEpisodeSize = 150 * 1024
1111

12+
public func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
13+
let bytesSent = task.countOfBytesSent
14+
let isCellular = metrics.transactionMetrics.last?.isCellular ?? false
15+
16+
if bytesSent > 0 {
17+
let connectionType: CellularDataUsageManager.ConnectionType = isCellular ? .cellular : .wifi
18+
19+
DataManager.sharedManager.cellularDataUsageManager.add(
20+
bytesUploaded: bytesSent,
21+
operationType: .upload,
22+
connectionType: connectionType,
23+
sessionType: .background
24+
)
25+
}
26+
}
27+
1228
public func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
1329
// make sure we call the completion handler on the main queue, otherwise it will crash
1430
DispatchQueue.main.async {

0 commit comments

Comments
 (0)