@@ -47,15 +47,13 @@ class UserProfileCache {
47
47
@ NonNull @ VisibleForTesting protected final DiskCache diskCache ;
48
48
@ NonNull private final Logger logger ;
49
49
@ NonNull private final Map <String , Map <String , Object >> memoryCache ;
50
- @ NonNull private final LegacyDiskCache legacyDiskCache ;
51
50
52
- UserProfileCache (@ NonNull DiskCache diskCache , @ NonNull Logger logger ,
53
- @ NonNull Map < String , Map < String , Object >> memoryCache ,
54
- @ NonNull LegacyDiskCache legacyDiskCache ) {
51
+ UserProfileCache (@ NonNull DiskCache diskCache ,
52
+ @ NonNull Logger logger ,
53
+ @ NonNull Map < String , Map < String , Object >> memoryCache ) {
55
54
this .logger = logger ;
56
55
this .diskCache = diskCache ;
57
56
this .memoryCache = memoryCache ;
58
- this .legacyDiskCache = legacyDiskCache ;
59
57
}
60
58
61
59
/**
@@ -85,49 +83,6 @@ Map<String, Object> lookup(String userId) {
85
83
return memoryCache .get (userId );
86
84
}
87
85
88
- /**
89
- * Migrate legacy user profiles if found.
90
- * <p>
91
- * Note: this will overwrite a newer `UserProfile` cache in the unlikely event that a legacy cache and new cache
92
- * both exist on disk.
93
- */
94
- @ VisibleForTesting
95
- void migrateLegacyUserProfiles () {
96
- JSONObject legacyUserProfilesJson = legacyDiskCache .load ();
97
-
98
- if (legacyUserProfilesJson == null ) {
99
- logger .info ("No legacy user profiles to migrate." );
100
- return ;
101
- }
102
-
103
- try {
104
- Iterator <String > userIdIterator = legacyUserProfilesJson .keys ();
105
- while (userIdIterator .hasNext ()) {
106
- String userId = userIdIterator .next ();
107
- JSONObject legacyUserProfileJson = legacyUserProfilesJson .getJSONObject (userId );
108
-
109
- Map <String , Map <String , String >> experimentBucketMap = new ConcurrentHashMap <>();
110
- Iterator <String > experimentIdIterator = legacyUserProfileJson .keys ();
111
- while (experimentIdIterator .hasNext ()) {
112
- String experimentId = experimentIdIterator .next ();
113
- String variationId = legacyUserProfileJson .getString (experimentId );
114
- Map <String , String > decisionMap = new ConcurrentHashMap <>();
115
- decisionMap .put (variationIdKey , variationId );
116
- experimentBucketMap .put (experimentId , decisionMap );
117
- }
118
-
119
- Map <String , Object > userProfileMap = new ConcurrentHashMap <>();
120
- userProfileMap .put (userIdKey , userId );
121
- userProfileMap .put (experimentBucketMapKey , experimentBucketMap );
122
- save (userProfileMap );
123
- }
124
- } catch (JSONException e ) {
125
- logger .warn ("Unable to deserialize legacy user profiles. Will delete legacy user profile cache file." , e );
126
- } finally {
127
- legacyDiskCache .delete ();
128
- }
129
- }
130
-
131
86
/**
132
87
* Remove a user profile.
133
88
*
@@ -218,9 +173,6 @@ void save(Map<String, Object> userProfileMap) {
218
173
* Load the cache from disk to memory.
219
174
*/
220
175
void start () {
221
- // Migrate legacy user profiles if found.
222
- migrateLegacyUserProfiles ();
223
-
224
176
try {
225
177
JSONObject userProfilesJson = diskCache .load ();
226
178
Map <String , Map <String , Object >> userProfilesMap = UserProfileCacheUtils .convertJSONObjectToMap
@@ -295,71 +247,4 @@ protected Boolean doInBackground(Void[] params) {
295
247
task .executeOnExecutor (executor );
296
248
}
297
249
}
298
-
299
- /**
300
- * Stores a map of userIds to a map of expIds to variationIds in a file.
301
- *
302
- * @deprecated This class is only used to migrate legacy user profiles to the new {@link UserProfileCache}.
303
- */
304
- static class LegacyDiskCache {
305
-
306
- private static final String FILE_NAME = "optly-user-profile-%s.json" ;
307
- @ NonNull private final Cache cache ;
308
- @ NonNull private final Executor executor ;
309
- @ NonNull private final Logger logger ;
310
- @ NonNull private final String projectId ;
311
-
312
- LegacyDiskCache (@ NonNull Cache cache , @ NonNull Executor executor , @ NonNull Logger logger ,
313
- @ NonNull String projectId ) {
314
- this .cache = cache ;
315
- this .executor = executor ;
316
- this .logger = logger ;
317
- this .projectId = projectId ;
318
- }
319
-
320
- @ VisibleForTesting
321
- String getFileName () {
322
- return String .format (FILE_NAME , projectId );
323
- }
324
-
325
- /**
326
- * Load legacy user profiles from disk if found.
327
- */
328
- @ Nullable
329
- JSONObject load () {
330
- String cacheString = cache .load (getFileName ());
331
-
332
- if (cacheString == null ) {
333
- logger .info ("Legacy user profile cache not found." );
334
- return null ;
335
- }
336
-
337
- try {
338
- return new JSONObject (cacheString );
339
- } catch (JSONException e ) {
340
- logger .warn ("Unable to parse legacy user profiles. Will delete legacy user profile cache file." , e );
341
- delete ();
342
- return null ;
343
- }
344
- }
345
-
346
- /**
347
- * Delete the legacy user profile cache from disk in a background thread.
348
- */
349
- void delete () {
350
- AsyncTask <Void , Void , Boolean > task = new AsyncTask <Void , Void , Boolean >() {
351
- @ Override
352
- protected Boolean doInBackground (Void [] params ) {
353
- Boolean deleted = cache .delete (getFileName ());
354
- if (deleted ) {
355
- logger .info ("Deleted legacy user profile from disk." );
356
- } else {
357
- logger .warn ("Unable to delete legacy user profile from disk." );
358
- }
359
- return deleted ;
360
- }
361
- };
362
- task .executeOnExecutor (executor );
363
- }
364
- }
365
250
}
0 commit comments