Skip to content

Conversation

@dustinbyrne
Copy link
Contributor

Summary

  • Add get_feature_flag_result method that returns a FeatureFlagResult object containing enabled state, variant, and payload in a single call
  • Deprecate get_feature_flag_payload in favor of the new unified method
  • Optimize feature flag lookup in get_feature_flag from O(n) to O(1) by using the existing @feature_flags_by_key hash

Motivation

Previously, getting a flag's value and payload required two separate calls:

value = client.get_feature_flag('my-flag', 'user-123')
payload = client.get_feature_flag_payload('my-flag', 'user-123')

The new method returns both in one call:

result = client.get_feature_flag_result('my-flag', 'user-123')
result.enabled?  # => true
result.variant   # => 'control' (or nil for boolean flags)
result.payload   # => { 'discount' => 10 }
result.value     # => variant if present, otherwise enabled

Related to PostHog/posthog#43520

@dustinbyrne dustinbyrne force-pushed the feat/get-feature-flag-result branch 2 times, most recently from f91a3f2 to 2a7fdce Compare January 23, 2026 03:52
@dustinbyrne dustinbyrne marked this pull request as ready for review January 26, 2026 20:57
@dustinbyrne dustinbyrne requested a review from a team January 26, 2026 21:00
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Jan 26, 2026
Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

Generally great; Ruby is a fun language! I liked the factory method and FeatureFlagResult design in general, and the O(n) -> O(1) optimization is a nice bonus.

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Jan 27, 2026
@dustinbyrne dustinbyrne force-pushed the feat/get-feature-flag-result branch from 49612a3 to 2a7fdce Compare January 28, 2026 18:18
This method returns flag evaluation results including enabled, variant,
payload. It replaces cases where a flag must be checked before making a
second call to retrieve its payload.
@dustinbyrne dustinbyrne force-pushed the feat/get-feature-flag-result branch from 2a7fdce to 3253540 Compare January 28, 2026 18:34
@dustinbyrne dustinbyrne merged commit a4ea014 into main Jan 28, 2026
11 checks passed
@dustinbyrne dustinbyrne deleted the feat/get-feature-flag-result branch January 28, 2026 18:36
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants