Migrate EnvironmentUrlsKey to pref storage (#725)

This commit is contained in:
Kyle Spearrin 2020-02-10 11:32:58 -05:00 committed by GitHub
parent bbd8615cda
commit 89f26bbc6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View file

@ -30,8 +30,15 @@ namespace Bit.App.Services
Constants.MigratedFromV1AutofillPromptShown,
Constants.TriedV1Resync,
Constants.ClearCiphersCacheKey,
Constants.EnvironmentUrlsKey,
};
private readonly HashSet<string> _migrateToPreferences = new HashSet<string>
{
Constants.EnvironmentUrlsKey,
};
private readonly HashSet<string> _haveMigratedToPreferences = new HashSet<string>();
public MobileStorageService(
IStorageService preferenceStorageService,
IStorageService liteDbStorageService)
@ -40,13 +47,28 @@ namespace Bit.App.Services
_liteDbStorageService = liteDbStorageService;
}
public Task<T> GetAsync<T>(string key)
public async Task<T> GetAsync<T>(string key)
{
if(_preferenceStorageKeys.Contains(key))
{
return _preferencesStorageService.GetAsync<T>(key);
var prefValue = await _preferencesStorageService.GetAsync<T>(key);
if(prefValue != null || !_migrateToPreferences.Contains(key) ||
_haveMigratedToPreferences.Contains(key))
{
return prefValue;
}
}
return _liteDbStorageService.GetAsync<T>(key);
var liteDbValue = await _liteDbStorageService.GetAsync<T>(key);
if(_migrateToPreferences.Contains(key))
{
if(liteDbValue != null)
{
await _preferencesStorageService.SaveAsync(key, liteDbValue);
await _liteDbStorageService.RemoveAsync(key);
}
_haveMigratedToPreferences.Add(key);
}
return liteDbValue;
}
public Task SaveAsync<T>(string key, T obj)

View file

@ -13,7 +13,8 @@ namespace Bit.App.Services
private readonly string _sharedName;
private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
};
public PreferencesStorageService(string sharedName)