Repository navigation
Refactor MGLMapboxEvents - #1491
Conversation
|
I’m placing this PR on beta 2 for now, given its size, but I’m open to pulling it into beta 1 if we get enough testing. |
|
When metric collections is paused/disabled, is there any plan to to avoid calls to convert point to lat long, create dictionaries etc? This computation is not really necessary if collection is paused or disabled by the user . |
|
Good stuff @1ec5!
Totally agree with this decision. Let's not rush things at this stage of the game, especially with something this big. 👍 |
With these changes, none of that work should be happening. Most of it is guarded by Incidentally, the rather aggressive approach to jettisoning data on pause means we do need to rebuild all this data on resume. If you’re interested, this is a good opportunity to profile |
|
I am specifically referrring calls to selectors like the two following in MGLMapView.mm. Will calls to these also be protected if collection is paused?
|
|
In my rudimentary testing/profiling with quite a bit of finger-mashing, |
|
Thank you very much @1ec5 for kindly clarifying all my queries. I really appreciate it. |
631fa13 to
3a9b03d
Compare
`-[MGLMapboxEvents init]` only gets called if `-[MGLMapboxEvents sharedManager]` sees that user defaults call for an `MGLMapboxEvents` to be created. But those user defaults were only being registered inside `-[MGLMapboxEvents init]`. This change moves the registration to `+initialize`, which is called as soon as the class is loaded.
Removed “get” from names of methods that perform no network or file access.
The shared `MGLMapboxEvents` now owns the only instance of `MGLMetricsLocationManager`. It also owns a `MGLMapboxEventsData` object, to which all user-specific data has been relegated. This object can be built up and torn down on the fly, whenever the opt-out preference is toggled. `MGLMapboxEvents` has also given up knowledge of the access token and now queries `MGLAccountManager` for that information, which `MGLMapView` keeps up-to-date.
`MGLMetricsLocationManager` was nothing but overhead for `CLLocationManager`. Also removed an unused method.
Moved constant values from ivars into constants. Invalidate the flush timer and clear the event queue on pause. Rewrote some flush logic to be easier to follow.
As soon as the user returns to the host app after changing the opt-out preference in Settings, `MGLMapboxEvents` responds by pausing or resuming. Also moved the IB designables agent check to occur only once, at launch, since the process name is not expected to change mid-session.
`MGLMapboxEvents` automatically recreates its location manager when the host app is reauthorized for Location Services. Added some redundancy to ensure that there is no location manager when either Location Services or Mapbox Metrics is off.
3a9b03d to
54a703b
Compare
|
I just rebased and force-pushed this branch due to some reverts on master. |
|
Note when merging: this assertion needs to stay in |
refs #1491: iOS metrics testing
There was a problem hiding this comment.
Is there potential here for this call to be optimized away by ARC since it's not referred to strongly anywhere? Dumb idea, but curious about it.
There was a problem hiding this comment.
No, the actual object is held by a static global, so it will never go away for the lifetime of the process.
Enable Mapbox Metrics by default when Settings.bundle is absent, but allow Settings.bundle to override the default. Don’t register defaults for non-Mapbox preferences. The two-phase registration ensures that the defaults don’t default to unexpected values, yet gives the developer a chance to call `+[MGLAccountManager mapboxMetricsEnabledSettingShownInApp]` before the hard assertion. Fixes #1518.
There was a problem hiding this comment.
Do we lose some sort of fallback ability here for when the values were nil in the old code?
There was a problem hiding this comment.
These properties are now set unconditionally in -init based on Info.plist fields that are required for the app to launch. Even if they’re nil for some reason, you’d wind up with a user agent string that starts with “(null)/(null)/(null)”. The old code would simply return nil and crash when inserted into the HTTP request.
|
This feels really solid @1ec5 in code review. Easy to wrap the head around and good improvements made. Doing some testing now. |
Renamed the property to be consistent with the public class methods. Also removed a spurious #import of a .m file.
1. Always bail early if in IB. 2. Always run on main thread if not already. 3. THEN dispatch_once to create the static instance.
|
Plan of attack here per chat with @bleege is to merge this to |
refactor metrics system to immediately jettison data & tracking when users opt out
refs #1491: iOS metrics testing
refactor metrics system to immediately jettison data & tracking when users opt out
MGLMetricsLocationManager.h was removed upstream in mapbox/mapbox-gl-native#1491.
This is a significant refactoring of
MGLMapboxEventsthat ensures it only hangs onto user-specific data when permitted. It consolidates logic around enabling and disabling services and removes some indirection that made it difficult to understand ownership and lifespan of those services. The salient behavioral changes are:MGLMapboxEventsshuts off as soon as the user opts out. (If the user opt-out is implemented in Settings, it shuts off as soon as the user returns to the host app.)MGLMapboxEventsrestarts its location manager as soon as the user returns to the host app.MGLMapboxEventsdefaults to sending events even if the developer has failed to implement a user opt-out.Architectural improvements include:
MGLMetricsLocationManagersingleton no longer exists.MGLMapboxEventsis the clearinghouse for all Metrics-related logic.MGLMapboxEventsis paused.MGLMapboxMetricsno longer stores the access token separately. Instead, it gets it fromMGLAccountManager.MGLMapViewforwards access tokens toMGLAccountManageras well.Some things to test (please chime in if you can think of anything else):
MGLMapboxAcccountTypes+[MGLAccountManager setAccessToken:]and/or-[MGLMapView setAccessToken:]– ensureMGLAccountManager,MGLMapView, andMGLMapboxEventsare all aware of access token changes/cc @bleege @jfirebaugh @incanus