Skip to content

Commit 56a041b

Browse files
committed
up
1 parent fc31565 commit 56a041b

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

core-api/src/main/java/com/optimizely/ab/bucketing/DecisionService.java

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public DecisionResponse<Variation> getVariation(@Nonnull Experiment experiment,
132132

133133
if (variation != null) {
134134
if (userProfileTracker != null) {
135-
updateUserProfile(experiment, variation, userProfileTracker.userProfile);
136-
userProfileTracker.profileUpdated = true;
135+
userProfileTracker.updateUserProfile(experiment, variation);
137136
} else {
138137
logger.debug("This decision will not be saved since the UserProfileService is null.");
139138
}
@@ -233,14 +232,32 @@ private UserProfile getUserProfile(String userId, DecisionReasons reasons) {
233232
return userProfile;
234233
}
235234

236-
static class UserProfileTracker {
235+
class UserProfileTracker {
237236
public UserProfile userProfile;
238237
public boolean profileUpdated;
239238

240239
UserProfileTracker(UserProfile userProfile, boolean profileUpdated) {
241240
this.userProfile = userProfile;
242241
this.profileUpdated = profileUpdated;
243242
}
243+
244+
void updateUserProfile(@Nonnull Experiment experiment,
245+
@Nonnull Variation variation) {
246+
247+
String experimentId = experiment.getId();
248+
String variationId = variation.getId();
249+
Decision decision;
250+
if (userProfile.experimentBucketMap.containsKey(experimentId)) {
251+
decision = userProfile.experimentBucketMap.get(experimentId);
252+
decision.variationId = variationId;
253+
} else {
254+
decision = new Decision(variationId);
255+
}
256+
userProfile.experimentBucketMap.put(experimentId, decision);
257+
profileUpdated = true;
258+
logger.info("Updated variation \"{}\" of experiment \"{}\" for user \"{}\".",
259+
variationId, experimentId, userProfile.userId);
260+
}
244261
}
245262

246263
/**
@@ -495,31 +512,6 @@ DecisionResponse<Variation> getStoredVariation(@Nonnull Experiment experiment,
495512
}
496513
}
497514

498-
/**
499-
* Save a {@link Variation} of an {@link Experiment} for a user in the {@link UserProfileService}.
500-
*
501-
* @param experiment The experiment the user was buck
502-
* @param variation The Variation to save.
503-
* @param userProfile A {@link UserProfile} instance of the user information.
504-
*/
505-
void updateUserProfile(@Nonnull Experiment experiment,
506-
@Nonnull Variation variation,
507-
@Nonnull UserProfile userProfile) {
508-
509-
String experimentId = experiment.getId();
510-
String variationId = variation.getId();
511-
Decision decision;
512-
if (userProfile.experimentBucketMap.containsKey(experimentId)) {
513-
decision = userProfile.experimentBucketMap.get(experimentId);
514-
decision.variationId = variationId;
515-
} else {
516-
decision = new Decision(variationId);
517-
}
518-
userProfile.experimentBucketMap.put(experimentId, decision);
519-
logger.info("Updated variation \"{}\" of experiment \"{}\" for user \"{}\".",
520-
variationId, experimentId, userProfile.userId);
521-
}
522-
523515
/**
524516
* Save a {@link Variation} of an {@link Experiment} for a user in the {@link UserProfileService}.
525517
*

0 commit comments

Comments
 (0)