Skip to content

Commit

Permalink
Fix workout query
Browse files Browse the repository at this point in the history
  • Loading branch information
christophhagen committed Mar 14, 2024
1 parent c65c171 commit b1f45d1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Sources/HKDatabase/Database/HKDatabaseStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,11 @@ public final class HKDatabaseStore {
let endTime = end.timeIntervalSinceReferenceDate

let query = workouts.table
.join(.leftOuter, samples.table, on: workouts.table[workouts.dataId] == samples.table[samples.dataId])
.filter(samples.table[samples.startDate] <= endTime &&
.join(.leftOuter, samples.table,
on: workouts.table[workouts.dataId] == samples.table[samples.dataId])
.join(.leftOuter, objects.table,
on: samples.table[samples.dataId] == objects.table[objects.dataId])
.filter(samples.table[samples.startDate] <= endTime &&
samples.table[samples.endDate] >= startTime)
return try database.prepare(query).map(workout)
}
Expand All @@ -651,10 +654,14 @@ public final class HKDatabaseStore {

// Select only workouts where the primary activity has the correct type
let query = workouts.table
.join(.leftOuter, samples.table, on: workouts.table[workouts.dataId] == samples.table[samples.dataId])
.join(.leftOuter, samples.table,
on: workouts.table[workouts.dataId] == samples.table[samples.dataId])
.filter(samples.table[samples.startDate] <= endTime &&
samples.table[samples.endDate] >= startTime)
.join(.leftOuter, workoutActivities.table, on: workouts.table[workouts.dataId] == workoutActivities.table[workoutActivities.ownerId])
.join(.leftOuter, objects.table,
on: samples.table[samples.dataId] == objects.table[objects.dataId])
.join(.leftOuter, workoutActivities.table,
on: workouts.table[workouts.dataId] == workoutActivities.table[workoutActivities.ownerId])
.filter(workoutActivities.table[workoutActivities.activityType] == typeId &&
workoutActivities.table[workoutActivities.isPrimaryActivity] == true)
return try database.prepare(query)
Expand Down

0 comments on commit b1f45d1

Please sign in to comment.