Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refact: Refactored Forced decision #287

Merged
merged 14 commits into from
Dec 2, 2021

Conversation

mnoman09
Copy link
Contributor

@mnoman09 mnoman09 commented Nov 30, 2021

Summary

  • Refactored code and fixed some minor issues.
  • Introduced ForcedDecisionStore class that will be used for storing forced decisions.
  • Removed DecisionKey, instead introduced map of map in forceddecisionstore class.
  • GetFlagVariationKey removed from optimizely method, single source of truth for all mappings is DatafileProjectConfig class
  • Added config in the FindValidatedForcedDecision since no access of ProjectConfig directly from OptimizelyUserContext.
  • Refactored DecisionService, not needed for GetVariationFromExperimentRules or GetVariationFromDeliveryRules etc ...
  • No need of Separate mapping method in DatafileProjectConfig, tried to use existing maps to prepare FlagVariationsMap.
  • Documentation corrected.

Test plan

All FSC and unit tests should pass

Issues

  • I still see a little room of refactoring in DecisionService but for now this is fine.

}

public OptimizelyUserContext(Optimizely optimizely, string userId, UserAttributes userAttributes, Dictionary<string, OptimizelyForcedDecision> forcedDecisions, IErrorHandler errorHandler, ILogger logger)
public OptimizelyUserContext(Optimizely optimizely, string userId, UserAttributes userAttributes, ForcedDecisionsStore forcedDecisionsStore, IErrorHandler errorHandler, ILogger logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this constructor method? @jaeopt a question for you.

@msohailhussain msohailhussain marked this pull request as ready for review November 30, 2021 18:50
@msohailhussain msohailhussain requested a review from a team as a code owner November 30, 2021 18:50
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor looks good! Some changes suggested.

OptimizelySDK/ForcedDecisionsStore.cs Outdated Show resolved Hide resolved
Comment on lines 54 to +57
Logger = logger;
Optimizely = optimizely;
Attributes = userAttributes ?? new UserAttributes();
ForcedDecisionsMap = forcedDecisions ?? new Dictionary<string, OptimizelyForcedDecision>();
ForcedDecisionsStore = forcedDecisionsStore ?? new ForcedDecisionsStore();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need make a copy of forcedDecisionsStore (just like "attributes" copy) since they can be changed after user context copied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider optimization as well - most user contexts do not use ForcedDecision, so we can avoid instantiating/copying FDStore when not used at all.
java-sdk impl as a reference https://github.com/optimizely/java-sdk/blob/master/core-api/src/main/java/com/optimizely/ab/OptimizelyUserContext.java

OptimizelySDK/OptimizelyUserContext.cs Show resolved Hide resolved
OptimizelySDK/OptimizelyUserContext.cs Outdated Show resolved Hide resolved
OptimizelySDK/Config/DatafileProjectConfig.cs Show resolved Hide resolved
@dustin-sier
Copy link
Contributor

LGTM, appreciate the changes

@msohailhussain msohailhussain requested a review from jaeopt December 2, 2021 18:34
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the missing else

{
copiedForcedDecisionsStore = ForcedDecisionsStore.NullForcedDecision();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'else' missing

@msohailhussain msohailhussain merged commit d359a0f into dsier/forcedDecisions Dec 2, 2021
@msohailhussain msohailhussain deleted the mnoman/forcedDecisionRefact branch December 2, 2021 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants