beeminder / BeeSwift

Official Beeminder for iOS app
Other
30 stars 6 forks source link

HealthKit integration info stored by goalname (and not getting cleared when a goal's deleted) #23

Open bsoule opened 4 years ago

bsoule commented 4 years ago
### Desiderata
- [ ] Replicata?

A user created a goal and connected to Apple Health.

Then they changed their mind, deleted the goal, and made a new one with the same name.

The app then continued to send HealthKit data (that they didn't want) to the new goal.

(possibly sort of a problem with the beeminder api and that we use goal slug as the primary identifier... anyhow. does removing healthkit info from a goal work now? perhaps if that'd worked as expected they mightn't have deleted the original goal?)

Verbata: autodata maintenance, Apple Health integration, stupidly indexing by goalname instead of UUID,

krugerk commented 4 years ago

If this is an app-side only issue, I could image the following scenario:

User creates a goal and eventually uses the iOS App to link that goal with a HealthKit metric. As is (v 5.6.4), each time the app shows the gallery (and in a few other instances) all goals for a user are fetched. Upon successfully downloading the data representing the goals, the app configures any HeathKit integrations for the goals. It would be at this point that a "update goal with data from HK metric" event is scheduled with HK. If in the meantime the use deleted said goal replacing it with another under the same slug and did not load the app (the gallery with the list of goals), then the app would not reconfigure HK according to the new(ly updated) goals. Thus it could perhaps happen that HK triggers with new data, passing it along to a goal of matching slug, which is now a new goal.

I am not quite to the point where I am testing the HK integration thoroughly, I just noticed something similar having recently removed a goal (via the website) and created a new one (named the same, via the website). In my case, I had the goal screen open showing the old goal and the app was happy to send new data (entered at that screen) to the new goal of the same slug although it was a new goal. It might not hurt for the API to handle this - pass around data corresponding to unique goal IDs and not just slugs.

andrewpbrett commented 4 years ago

Another report of this one:

I created this goal previously and had linked it to the health app. I then deleted it and created a new goal which I would enter data manually for. However, since the name of the old goal (integrated with health) and the new goal were the same, it seems that Apple health continued to transfer data to this new goal, even though it is not connected to Apple Health.

krugerk commented 7 hours ago

I think this may no longer be an issue. There has since been the (re-)introduction of Core Data and the link goal to HealthKit is made over the NSManagedObjectID: https://github.com/beeminder/BeeSwift/blob/dcae107745940f6b35d28af01e933f1eb22ad1a5/BeeKit/Managers/HealthStoreManager.swift#L57 and the goals themselves are separated by goal ID: https://github.com/beeminder/BeeSwift/blob/dcae107745940f6b35d28af01e933f1eb22ad1a5/BeeKit/Managers/GoalManager.swift#L103

Previously this issue was easy to reproduce. I tested specifically for it recently (6.7 (51)) and have not noticed the issue.