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

[FSSDK-10763] Implement UPS request batching for decideForKeys #440

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

FarhanAnjum-opti
Copy link
Contributor

Summary

  • Currently, decideForKeys loops over the list of flags and calls decide for each, which in turn calls ups. So for decideForKeys, there is two calls per flag to UPS. This PR batches UPS calls when using decideForKeys.

Test plan

  • Existing tests are updated to work with the new change. New tests will be added for batching.

Issues

  • FSSDK-10763

…file` in decision logic.

🛠️ optimizely/user_profile.py -> Improved user profile loading with missing key checks.
🛠️ tests/test_decision_service.py -> Updated tests to include user profile tracker.
🛠️ tests/test_decision_service.py -> Updated experiment bucket map call.
🛠️ tests/test_decision_service.py -> Introduced user_profile_tracker usage.
🛠️ tests/test_decision_service.py -> Modified method calls with user_profile_tracker.
tests/test_decision_service.py -> Added user profile tracker object
tests/test_decision_service.py -> Fixed tests
Copy link
Contributor

@Mat001 Mat001 left a comment

Choose a reason for hiding this comment

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

Looks great! Just please cleanup old commented out pieces. Then we'll merge once done :)

optimizely/decision_service.py Outdated Show resolved Hide resolved
optimizely/optimizely.py Outdated Show resolved Hide resolved
optimizely/optimizely.py Outdated Show resolved Hide resolved
optimizely/optimizely.py Outdated Show resolved Hide resolved
optimizely/user_profile.py Outdated Show resolved Hide resolved
optimizely/user_profile.py Show resolved Hide resolved
tests/test_user_context.py Outdated Show resolved Hide resolved
self.user_profile_service.save(user_profile.__dict__)
user_profile_tracker.update_user_profile(experiment, variation)
if self.user_profile_service is not None:
self.user_profile_service.save(user_profile_tracker.get_user_profile().__dict__)

Choose a reason for hiding this comment

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

This will cause the user profile service to be saved for each flag key, making the batching save ineffective. This if block should be removed

@@ -629,8 +632,11 @@ def get_variation(
return None

user_context = OptimizelyUserContext(self, self.logger, user_id, attributes, False)

variation, _ = self.decision_service.get_variation(project_config, experiment, user_context)
user_profile_tracker = user_profile.UserProfileTracker(user_id, self.user_profile_service, self.logger)

Choose a reason for hiding this comment

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

should there be a user_profile_service.load_user_profile() call here. I suspect this could be a reason behind FSC failures

variation, _ = self.decision_service.get_variation(project_config,
experiment,
user_context,
user_profile_tracker)

Choose a reason for hiding this comment

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

the user profile should be saved here as we will remove the save from get_variation() in decision service.

optimizely/optimizely.py -> Added loading and saving profile logic
optimizely/user_profile.py -> Testing user profile update logic
optimizely/user_profile.py -> Removed unused import statement
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.

3 participants