Skip to content
Open
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
26 changes: 18 additions & 8 deletions Sources/Cacheout/ViewModels/CacheoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ class CacheoutViewModel: ObservableObject {
func scan() async {
isScanning = true
isNodeModulesScanning = true
diskInfo = DiskInfo.current()

// ⚑ Bolt: Offload synchronous file system call to prevent blocking the @MainActor
// Impact: Keeps the UI responsive (avoiding a ~5-10ms hitch) during initial scan
diskInfo = await Task.detached { DiskInfo.current() }.value

// Scan caches and node_modules in parallel
async let cacheResults = scanner.scanAll(CacheCategory.allCategories)
Expand Down Expand Up @@ -241,12 +244,18 @@ class CacheoutViewModel: ObservableObject {
]

do {
try process.run()
process.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8) ?? ""

if process.terminationStatus == 0 {
// ⚑ Bolt: Offload blocking I/O (process.run, waitUntilExit, readDataToEndOfFile)
// Impact: Prevents the @MainActor from freezing during the entire Docker prune execution,
// which can take several seconds to complete. Keeps the UI completely responsive.
let (output, terminationStatus) = try await Task.detached {
try process.run()
process.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8) ?? ""
return (output, process.terminationStatus)
}.value

if terminationStatus == 0 {
// Extract "Total reclaimed space:" line
if let line = output.components(separatedBy: "\n")
.first(where: { $0.contains("reclaimed") }) {
Expand All @@ -270,7 +279,8 @@ class CacheoutViewModel: ObservableObject {
}

// Refresh disk info after prune
diskInfo = DiskInfo.current()
// ⚑ Bolt: Offload synchronous file system call
diskInfo = await Task.detached { DiskInfo.current() }.value
}

func clean() async {
Expand Down