diff options
| author | Christian Cleberg <[email protected]> | 2026-04-12 11:49:45 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-12 11:49:45 -0500 |
| commit | 9e48e4681487b1c69577c0e9e5f83d8d8225e494 (patch) | |
| tree | 825ce946dac13ad24a123b647722a6cab6c51599 /Hutch/Networking | |
| parent | c0744a35891f89e50ab407a0b8557ce9d5c5e6cc (diff) | |
| download | hutch-9e48e4681487b1c69577c0e9e5f83d8d8225e494.tar.gz hutch-9e48e4681487b1c69577c0e9e5f83d8d8225e494.tar.bz2 hutch-9e48e4681487b1c69577c0e9e5f83d8d8225e494.zip | |
feat: add prioritization of polling hutch-stats for logged in user
Diffstat (limited to 'Hutch/Networking')
| -rw-r--r-- | Hutch/Networking/HutchStatsService.swift | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/Hutch/Networking/HutchStatsService.swift b/Hutch/Networking/HutchStatsService.swift index 69a2a20..52d86b9 100644 --- a/Hutch/Networking/HutchStatsService.swift +++ b/Hutch/Networking/HutchStatsService.swift @@ -9,20 +9,23 @@ struct HutchStatsService: ContributionCalendarServing { private let session: URLSession private let decoder: JSONDecoder private let baseURL: URL + private let currentActor: String? init( session: URLSession = .shared, - configuration: AppConfiguration + configuration: AppConfiguration, + currentActor: String? = nil ) { self.session = session self.baseURL = configuration.hutchStatsBaseURL self.decoder = JSONDecoder() + self.currentActor = currentActor } func fetchContributionCalendar(actor: String, endingOn endDate: Date) async throws -> ContributionCalendarResponse { return try await fetch( path: "api/contributions/\(actor)", - queryItems: trailingYearQueryItems(endingOn: endDate), + queryItems: contributionQueryItems(actor: actor, endingOn: endDate), responseType: ContributionCalendarResponse.self ) } @@ -30,7 +33,7 @@ struct HutchStatsService: ContributionCalendarServing { func fetchContributionStats(actor: String, endingOn endDate: Date) async throws -> ContributionStatsResponse { return try await fetch( path: "api/contributions/\(actor)/stats", - queryItems: trailingYearQueryItems(endingOn: endDate), + queryItems: contributionQueryItems(actor: actor, endingOn: endDate), responseType: ContributionStatsResponse.self ) } @@ -86,15 +89,21 @@ struct HutchStatsService: ContributionCalendarServing { return normalizedStartDate...normalizedEndDate } - private func trailingYearQueryItems(endingOn endDate: Date) -> [URLQueryItem] { + func contributionQueryItems(actor: String, endingOn endDate: Date) -> [URLQueryItem] { let range = trailingRange(endingOn: endDate) let start = Self.rangeFormatter.string(from: range.lowerBound) let end = Self.rangeFormatter.string(from: range.upperBound) - return [ + var queryItems = [ URLQueryItem(name: "from", value: start), URLQueryItem(name: "to", value: end) ] + + if actor == currentActor { + queryItems.append(URLQueryItem(name: "prioritize", value: "self")) + } + + return queryItems } private static let rangeFormatter: DateFormatter = { |
