Skip to content

Commit b99bf0c

Browse files
committed
refactor: drop std::optional from IBigSegmentStore::GetMembershipResult
1 parent 0082f6e commit b99bf0c

4 files changed

Lines changed: 20 additions & 36 deletions

File tree

libs/server-sdk-dynamodb-source/src/dynamodb_big_segment_store.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ IBigSegmentStore::GetMembershipResult DynamoDBBigSegmentStore::GetMembership(
7979
}
8080

8181
auto const& item = outcome.GetResult().GetItem();
82-
if (item.empty()) {
83-
return std::nullopt;
84-
}
8582

8683
std::vector<std::string> included;
8784
std::vector<std::string> excluded;

libs/server-sdk-dynamodb-source/tests/dynamodb_big_segment_store_test.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ class DynamoDBBigSegmentTests : public ::testing::Test {
8585

8686
} // namespace
8787

88-
TEST_F(DynamoDBBigSegmentTests, EmptyStoreReturnsNoMembership) {
88+
TEST_F(DynamoDBBigSegmentTests, EmptyStoreReturnsEmptyMembership) {
8989
auto const result = store_->GetMembership("nobody");
9090
ASSERT_TRUE(result);
91-
ASSERT_FALSE(result->has_value());
91+
ASSERT_FALSE(result->CheckMembership("seg1.g1").has_value());
9292
}
9393

9494
TEST_F(DynamoDBBigSegmentTests, EmptyStoreReturnsNoMetadata) {
@@ -103,12 +103,10 @@ TEST_F(DynamoDBBigSegmentTests, GetMembershipWithIncludesOnly) {
103103

104104
auto const result = store_->GetMembership("alice");
105105
ASSERT_TRUE(result);
106-
ASSERT_TRUE(result->has_value());
107106

108-
auto const& m = result->value();
109-
ASSERT_EQ(m.CheckMembership("seg1.g1"), true);
110-
ASSERT_EQ(m.CheckMembership("seg2.g3"), true);
111-
ASSERT_FALSE(m.CheckMembership("seg3.g1").has_value());
107+
ASSERT_EQ(result->CheckMembership("seg1.g1"), true);
108+
ASSERT_EQ(result->CheckMembership("seg2.g3"), true);
109+
ASSERT_FALSE(result->CheckMembership("seg3.g1").has_value());
112110
}
113111

114112
TEST_F(DynamoDBBigSegmentTests, GetMembershipWithExcludesOnly) {
@@ -117,8 +115,7 @@ TEST_F(DynamoDBBigSegmentTests, GetMembershipWithExcludesOnly) {
117115

118116
auto const result = store_->GetMembership("bob");
119117
ASSERT_TRUE(result);
120-
ASSERT_TRUE(result->has_value());
121-
ASSERT_EQ(result->value().CheckMembership("seg1.g1"), false);
118+
ASSERT_EQ(result->CheckMembership("seg1.g1"), false);
122119
}
123120

124121
TEST_F(DynamoDBBigSegmentTests, GetMembershipInclusionWinsOverExclusion) {
@@ -127,8 +124,7 @@ TEST_F(DynamoDBBigSegmentTests, GetMembershipInclusionWinsOverExclusion) {
127124

128125
auto const result = store_->GetMembership("carol");
129126
ASSERT_TRUE(result);
130-
ASSERT_TRUE(result->has_value());
131-
ASSERT_EQ(result->value().CheckMembership("seg.g1"), true);
127+
ASSERT_EQ(result->CheckMembership("seg.g1"), true);
132128
}
133129

134130
TEST_F(DynamoDBBigSegmentTests, GetMembershipIsPrefixScoped) {
@@ -137,7 +133,7 @@ TEST_F(DynamoDBBigSegmentTests, GetMembershipIsPrefixScoped) {
137133

138134
auto const result = store_->GetMembership("alice");
139135
ASSERT_TRUE(result);
140-
ASSERT_FALSE(result->has_value());
136+
ASSERT_FALSE(result->CheckMembership("seg1.g1").has_value());
141137
}
142138

143139
TEST_F(DynamoDBBigSegmentTests, GetMembershipRejectsMalformedIncluded) {

libs/server-sdk-redis-source/tests/redis_big_segment_store_test.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ class RedisBigSegmentTests : public ::testing::Test {
7575
TEST_F(RedisBigSegmentTests, EmptyStoreReturnsEmptyMembership) {
7676
auto const result = store_->GetMembership("nobody");
7777
ASSERT_TRUE(result);
78-
ASSERT_TRUE(result->has_value());
79-
ASSERT_FALSE(result->value().CheckMembership("seg1.g1").has_value());
78+
ASSERT_FALSE(result->CheckMembership("seg1.g1").has_value());
8079
}
8180

8281
TEST_F(RedisBigSegmentTests, EmptyStoreReturnsNoMetadata) {
@@ -90,23 +89,18 @@ TEST_F(RedisBigSegmentTests, GetMembershipWithIncludesOnly) {
9089

9190
auto const result = store_->GetMembership("alice");
9291
ASSERT_TRUE(result);
93-
ASSERT_TRUE(result->has_value());
9492

95-
auto const& m = result->value();
96-
ASSERT_EQ(m.CheckMembership("seg1.g1"), true);
97-
ASSERT_EQ(m.CheckMembership("seg2.g3"), true);
98-
ASSERT_FALSE(m.CheckMembership("seg3.g1").has_value());
93+
ASSERT_EQ(result->CheckMembership("seg1.g1"), true);
94+
ASSERT_EQ(result->CheckMembership("seg2.g3"), true);
95+
ASSERT_FALSE(result->CheckMembership("seg3.g1").has_value());
9996
}
10097

10198
TEST_F(RedisBigSegmentTests, GetMembershipWithExcludesOnly) {
10299
AddExcludes("bob", {"seg1.g1"});
103100

104101
auto const result = store_->GetMembership("bob");
105102
ASSERT_TRUE(result);
106-
ASSERT_TRUE(result->has_value());
107-
108-
auto const& m = result->value();
109-
ASSERT_EQ(m.CheckMembership("seg1.g1"), false);
103+
ASSERT_EQ(result->CheckMembership("seg1.g1"), false);
110104
}
111105

112106
TEST_F(RedisBigSegmentTests, GetMembershipInclusionWinsOverExclusion) {
@@ -115,8 +109,7 @@ TEST_F(RedisBigSegmentTests, GetMembershipInclusionWinsOverExclusion) {
115109

116110
auto const result = store_->GetMembership("carol");
117111
ASSERT_TRUE(result);
118-
ASSERT_TRUE(result->has_value());
119-
ASSERT_EQ(result->value().CheckMembership("seg.g1"), true);
112+
ASSERT_EQ(result->CheckMembership("seg.g1"), true);
120113
}
121114

122115
TEST_F(RedisBigSegmentTests, GetMembershipIsPrefixScoped) {
@@ -125,8 +118,7 @@ TEST_F(RedisBigSegmentTests, GetMembershipIsPrefixScoped) {
125118

126119
auto const result = store_->GetMembership("alice");
127120
ASSERT_TRUE(result);
128-
ASSERT_TRUE(result->has_value());
129-
ASSERT_FALSE(result->value().CheckMembership("seg1.g1").has_value());
121+
ASSERT_FALSE(result->CheckMembership("seg1.g1").has_value());
130122
}
131123

132124
TEST_F(RedisBigSegmentTests, GetMetadataReturnsSyncTime) {

libs/server-sdk/include/launchdarkly/server_side/integrations/big_segments/ibig_segment_store.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class IBigSegmentStore {
3838
IBigSegmentStore& operator=(IBigSegmentStore const&) = delete;
3939
IBigSegmentStore& operator=(IBigSegmentStore&&) = delete;
4040

41-
using GetMembershipResult =
42-
tl::expected<std::optional<Membership>, std::string>;
41+
using GetMembershipResult = tl::expected<Membership, std::string>;
4342
using GetMetadataResult =
4443
tl::expected<std::optional<StoreMetadata>, std::string>;
4544

@@ -49,10 +48,10 @@ class IBigSegmentStore {
4948
* @param context_hash Base64-encoded SHA-256 of the context key.
5049
* Implementations should treat this as an opaque identifier.
5150
*
52-
* @return A @ref Membership snapshot if the store has any record for this
53-
* context hash, `std::nullopt` if there is no record (which is a normal
54-
* case — most contexts are in no Big Segments), or an error if the lookup
55-
* itself failed.
51+
* @return A @ref Membership snapshot. Most contexts are in no Big
52+
* Segments, in which case the returned Membership has no entries (every
53+
* @ref Membership::CheckMembership call against it returns
54+
* `std::nullopt`). Returns an error if the lookup itself failed.
5655
*/
5756
[[nodiscard]] virtual GetMembershipResult GetMembership(
5857
std::string const& context_hash) const = 0;

0 commit comments

Comments
 (0)