mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
⚡️ Fix performance issue with async
This commit is contained in:
@ -20,16 +20,19 @@ struct HomebrewService: Decodable, Equatable {
|
||||
let error_log_path: String?
|
||||
|
||||
public static func loadAll(
|
||||
filter: [String] = [PhpEnv.phpInstall.formula, "nginx", "dnsmasq"]
|
||||
) async -> [HomebrewService] {
|
||||
return try! JSONDecoder().decode(
|
||||
[HomebrewService].self,
|
||||
from: Shell.pipe(
|
||||
"sudo \(Paths.brew) services info --all --json",
|
||||
requiresPath: true
|
||||
).data(using: .utf8)!
|
||||
).filter({ service in
|
||||
return filter.contains(service.name)
|
||||
})
|
||||
filter: [String] = [PhpEnv.phpInstall.formula, "nginx", "dnsmasq"],
|
||||
completion: @escaping ([HomebrewService]) -> Void
|
||||
) {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
let data = Shell
|
||||
.pipe("sudo \(Paths.brew) services info --all --json", requiresPath: true)
|
||||
.data(using: .utf8)!
|
||||
|
||||
let services = try! JSONDecoder()
|
||||
.decode([HomebrewService].self, from: data)
|
||||
.filter({ return filter.contains($0.name) })
|
||||
|
||||
completion(services)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,14 +46,15 @@ class ServicesView: NSView, XibLoadable {
|
||||
}
|
||||
|
||||
@objc func updateInformation() {
|
||||
Task { await self.loadData() }
|
||||
self.loadData()
|
||||
}
|
||||
|
||||
func loadData() async {
|
||||
self.applyAllInfoFieldsFromCachedValue()
|
||||
let services = await HomebrewService.loadAll()
|
||||
ServicesView.services = Dictionary(uniqueKeysWithValues: services.map{ ($0.name, $0) })
|
||||
func loadData() {
|
||||
self.applyAllInfoFieldsFromCachedValue()
|
||||
HomebrewService.loadAll { services in
|
||||
ServicesView.services = Dictionary(uniqueKeysWithValues: services.map{ ($0.name, $0) })
|
||||
self.applyAllInfoFieldsFromCachedValue()
|
||||
}
|
||||
}
|
||||
|
||||
func applyAllInfoFieldsFromCachedValue() {
|
||||
|
Reference in New Issue
Block a user