Open
Conversation
… guarded db interactions with apikey check
Amplitude/AMPUtils.m
Outdated
| NSError *error; | ||
| if (![fileManager fileExistsAtPath:to] && | ||
| [fileManager fileExistsAtPath:from]) { | ||
| if ([fileManager copyItemAtPath:from toPath:to error:&error]) { |
Member
|
LGTM, update readme |
Member
Author
|
RECAP of this PR's changes
PTAL @curtisliu |
Contributor
|
@djih close this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This mirrors the db file renaming work done on Android: https://github.com/amplitude/Amplitude-Android/pull/112/files
Tested the renaming on demo app on both simulator and real test device. Also tested that subsequent re-opening of app skips the renaming. Tested that all the database data was still intact (previous sessionId, last event time, deviceId, event id, etc). Added two unit tests as well.
A lot of the test updates is just fixing the call to
getDatabaseHelper. I added a new extra methodgetDatabaseHelperWithInstanceNamejust for testing, explicitly with a new name so that any uncaught calls to the oldgetDatabaseHelper:instanceNamewould not erroneously get mapped to the test method. The purpose of the test method is to re-generate the old database file, sidestepping the static _instances which I cannot access directly.We already have a helper method to move files around, so I just factored it out into AMPUtils.
Note: the new database filename is in the form
com.amplitude.database_instancename_apiKey. I was a little worried that the filename might become too long. iOS limits the full file path to 1024 chars, and the actual filename to 255 chars. On the actual test device, the full path looks like this:/var/mobile/Containers/Data/Application/85A9D80F-FA07-456F-A1CB-BD4C54145649/Library/com.amplitude.database_app2_c6fa6b27f515fb3f0e5ece6caf86027b, which is only 145 characters. So I think it's safe to use that format for the new name.This builds on top of #109. Comments from that PR:
We need to migrate any database interaction logic in the
initmethod into theinitializeApiKeymethod since we will need the apiKey to interact with the database. I also run theinitlogic on thebackgroundQueue, removing the need for a separateinitializerQueue.Few things to note:
_dbHelperis initialized ininitializeApiKeynow. Any public methods that interact with the database such assetUserId,setDeviceId,identify, etc need to be guarded with an apiKey check to ensure[self.dbHelper]is available[self addObservers]toinitializeApiKeysinceenterBackgroundinteracts with the DB by saving the current timestamp.