Skip to content

Commit

Permalink
Simplify query run title logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsochantaris committed Feb 26, 2024
1 parent 080df6e commit 8051d27
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Sources/trailer/Actions/Actions-Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ extension Actions {
return item
}

private static func run(_ query: Query, shouldRetry: Int = 5, asSubQuery: Bool = false) async throws {
private static func run(_ query: Query, shouldRetry: Int = 5) async throws {
func retryOrFail(_ message: String) async throws {
if shouldRetry > 1 {
log(level: .verbose, "[*\(query.name)*] \(message)")
Expand All @@ -548,10 +548,6 @@ extension Actions {
return nil
}

if shouldRetry == 5, !asSubQuery {
log("[*\(query.name)*] Fetching")
}

let info: Data
do {
let Q = query.queryText
Expand Down Expand Up @@ -601,11 +597,20 @@ extension Actions {
try await run(extraQueries, asSubQueries: true)
}

private static func run(_ queries: Lista<Query>, asSubQueries: Bool = false) async throws {
private static var lastRunTitle = ""
private static func run(_ queries: Lista<Query>, asSubQueries _: Bool = false) async throws {
guard let firstQuery = queries.first else {
return
}
let title = "[*\(firstQuery.name)*] Fetching"
if lastRunTitle != title {
lastRunTitle = title
log(title)
}
try await withThrowingTaskGroup(of: Void.self) { group in
for query in queries {
group.addTask {
try await run(query, asSubQuery: asSubQueries)
try await run(query)
}
}
try await group.waitForAll()
Expand Down

0 comments on commit 8051d27

Please sign in to comment.