Skip to content

Commit b43e10f

Browse files
refactor: SaveToUserProfileService for simplicity
1 parent f9f3f3f commit b43e10f

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

OptimizelySDK/Bucketing/DecisionService.cs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -518,36 +518,28 @@ private void SaveToUserProfileService(Experiment experiment = null,
518518
Variation variation = null
519519
)
520520
{
521-
var useSpecificLogEntry = experiment != null && variation != null &&
522-
!string.IsNullOrEmpty(_userProfile?.UserId);
523-
521+
var hasExperimentDetails = experiment != null && variation != null &&
522+
!string.IsNullOrEmpty(_userProfile.UserId);
524523
try
525524
{
526-
if (_userProfile != null)
525+
if (_userProfile == null)
527526
{
528-
UserProfileService.Save(_userProfile.ToMap());
529-
if (useSpecificLogEntry)
530-
{
531-
Logger.Log(LogLevel.INFO,
532-
$"Saved variation \"{variation.Id}\" of experiment \"{experiment.Id}\" for user \"{_userProfile.UserId}\".");
533-
}
534-
else
535-
{
536-
Logger.Log(LogLevel.INFO, "Saved user profile after batch decision.");
537-
}
527+
return;
538528
}
529+
530+
UserProfileService.Save(_userProfile.ToMap());
531+
532+
Logger.Log(LogLevel.INFO,
533+
hasExperimentDetails ?
534+
$"Saved variation \"{variation.Id}\" of experiment \"{experiment.Id}\" for user \"{_userProfile.UserId}\"." :
535+
"Saved user profile after batch decision.");
539536
}
540537
catch (Exception exception)
541538
{
542-
if (useSpecificLogEntry)
543-
{
544-
Logger.Log(LogLevel.ERROR,
545-
$"Failed to save variation \"{variation.Id}\" of experiment \"{experiment.Id}\" for user \"{_userProfile.UserId}\".");
546-
}
547-
else
548-
{
549-
Logger.Log(LogLevel.ERROR, "Failed to save user profile after batch decision.");
550-
}
539+
Logger.Log(LogLevel.ERROR,
540+
hasExperimentDetails ?
541+
$"Failed to save variation \"{variation.Id}\" of experiment \"{experiment.Id}\" for user \"{_userProfile.UserId}\"." :
542+
"Failed to save user profile after batch decision.");
551543

552544
ErrorHandler.HandleError(
553545
new Exceptions.OptimizelyRuntimeException(exception.Message));

0 commit comments

Comments
 (0)