Skip to content

Commit db3ea40

Browse files
committed
Revert some of the changes
1 parent c2d7092 commit db3ea40

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

Modules/Sources/JetpackStats/Cards/ChartCard.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct ChartCard: View {
7979
@ViewBuilder
8080
private var contentView: some View {
8181
VStack(spacing: Constants.step1) {
82-
if dateRange.comparison != .off {
82+
if dateRange.comparison != .off || metrics.count == 1 {
8383
chartHeaderView
8484
.padding(.trailing, -Constants.step0_5)
8585
}
@@ -92,7 +92,7 @@ struct ChartCard: View {
9292

9393
private var chartHeaderView: some View {
9494
// Showing currently selected (not loaded period) by design
95-
HStack(alignment: .top, spacing: 0) {
95+
HStack(alignment: .center, spacing: 0) {
9696
if let data = viewModel.chartData[selectedMetric] {
9797
ChartValuesSummaryView(
9898
trend: .make(data, context: .regular),

Modules/Sources/JetpackStats/Cards/ChartCardViewModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,18 @@ final class ChartCardViewModel: ObservableObject, TrafficCardViewModel {
165165

166166
let granularity = selectedGranularity ?? dateRange.dateInterval.preferredGranularity
167167

168-
let currentResponse = try await service.getSiteStats(
168+
// Fetch both current and previous period data concurrently
169+
async let currentResponseTask = service.getSiteStats(
169170
interval: dateRange.dateInterval,
170171
granularity: granularity
171172
)
172-
let previousResponse = try await service.getSiteStats(
173+
async let previousResponseTask = service.getSiteStats(
173174
interval: dateRange.effectiveComparisonInterval,
174175
granularity: granularity
175176
)
176177

178+
let (currentResponse, previousResponse) = try await (currentResponseTask, previousResponseTask)
179+
177180
for (metric, dataPoints) in currentResponse.metrics {
178181
let previousDataPoints = previousResponse.metrics[metric] ?? []
179182

Modules/Sources/JetpackStats/Cards/StandaloneChartCard.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct StandaloneChartCard: View {
9898
ChartLegendView(
9999
metric: metric,
100100
currentPeriod: dateRange.dateInterval,
101-
previousPeriod: dateRange.comparison != .off ? dateRange.effectiveComparisonInterval : nil
101+
previousPeriod: dateRange.effectiveComparisonInterval
102102
)
103103
}
104104
}

Modules/Sources/JetpackStats/Cards/TopListViewModel.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ final class TopListViewModel: ObservableObject, TrafficCardViewModel {
210210
}
211211

212212
// Fetch current data
213-
let current = try await service.getTopListData(
213+
async let currentTask = service.getTopListData(
214214
fetchItem,
215215
metric: selection.metric,
216216
interval: dateRange.dateInterval,
@@ -219,20 +219,22 @@ final class TopListViewModel: ObservableObject, TrafficCardViewModel {
219219
locationLevel: selection.locationLevel
220220
)
221221

222-
// Fetch previous data only for items that support it and if comparison is enabled
223-
let previous: TopListResponse?
224-
if dateRange.comparison != .off && selection.item != .archive {
225-
previous = try await service.getTopListData(
222+
// Fetch previous data only for items that support it
223+
async let previousTask: TopListResponse? = {
224+
guard selection.item != .archive && dateRange.comparison != .off else {
225+
return nil
226+
}
227+
return try await service.getTopListData(
226228
fetchItem,
227229
metric: selection.metric,
228230
interval: dateRange.effectiveComparisonInterval,
229231
granularity: granularity,
230232
limit: fetchLimit,
231233
locationLevel: selection.locationLevel
232234
)
233-
} else {
234-
previous = nil
235-
}
235+
}()
236+
237+
let (current, previous) = try await (currentTask, previousTask)
236238

237239
let currentItems = filteredItems(current.items)
238240
let previousItems = filteredItems(previous?.items ?? [])

0 commit comments

Comments
 (0)