Skip to content

Commit 3714934

Browse files
emyllerclaude
andcommitted
Remove legacy engine code
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3dc3cda commit 3714934

File tree

17 files changed

+8
-879
lines changed

17 files changed

+8
-879
lines changed

Flagsmith.Client.Test/FlagsmithTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public async Task TestGetEnvironmentFlagsUsesLocalEnvironmentWhenAvailable()
124124
var flags = (await flagsmithClientTest.GetEnvironmentFlags()).AllFlags();
125125
var fs = Fixtures.Environment.FeatureStates[0];
126126
Assert.Equal(fs.Enabled, flags[0].Enabled);
127-
Assert.Equal(fs.GetValue(), flags[0].Value);
127+
Assert.Equal(fs.Value, flags[0].Value);
128128
Assert.Equal(fs.Feature.Name, flags[0].GetFeatureName());
129129
mockHttpClient.VerifyHttpRequest(HttpMethod.Get, "/api/v1/environment-document/", Times.Once);
130130
}

Flagsmith.Engine/Feature/Models/FeatureStateModel.cs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using Newtonsoft.Json;
2-
using System;
32
using System.Collections.Generic;
4-
using System.Text;
5-
using FlagsmithEngine.Utils;
63
using System.Linq;
74
using System.Runtime.Serialization;
85
using FlagsmithEngine.Exceptions;
@@ -11,8 +8,6 @@ namespace FlagsmithEngine.Feature.Models
118
{
129
public class FeatureStateModel
1310
{
14-
public Hashing Hashing = new Hashing();
15-
1611
[JsonProperty(PropertyName = "feature")]
1712
public FeatureModel Feature { get; set; }
1813
[JsonProperty(PropertyName = "enabled")]
@@ -23,45 +18,11 @@ public class FeatureStateModel
2318
public List<MultivariateFeatureStateValueModel> MultivariateFeatureStateValues { get; set; }
2419
[JsonProperty(PropertyName = "django_id")]
2520
public int? DjangoId { get; set; }
26-
public string FeatureStateUUID { get; set; } = new Guid().ToString();
21+
[JsonProperty(PropertyName = "featurestate_uuid")]
22+
public string FeatureStateUUID { get; set; }
2723
[JsonProperty(PropertyName = "feature_segment")]
2824
public FeatureSegmentModel FeatureSegment { get; set; } = null;
29-
public object GetValue(string identityId = null) =>
30-
identityId != null && MultivariateFeatureStateValues?.Count > 0 ? GetMultivariateValue(identityId.ToString()) : Value;
31-
32-
public object GetMultivariateValue(string identityId)
33-
{
34-
var percentageValue = Hashing.GetHashedPercentageForObjectIds(new List<string>
35-
{
36-
DjangoId != null ? DjangoId.ToString() : FeatureStateUUID,
37-
identityId.ToString()
38-
});
39-
var startPercentage = 0.0;
40-
foreach (var myValue in MultivariateFeatureStateValues.OrderBy(m => m.Id))
41-
{
42-
var limit = myValue.PercentageAllocation + startPercentage;
43-
if (startPercentage <= percentageValue && percentageValue < limit)
44-
return myValue.MultivariateFeatureOption.Value;
45-
startPercentage = limit;
46-
}
47-
return Value;
48-
}
4925

50-
/// <summary>
51-
/// Another FeatureStateModel is deemed to be higher priority if and only if
52-
/// it has a FeatureSegment and either this.FeatureSegment is null or the
53-
/// value of other.FeatureSegment.priority is lower than that of
54-
/// this.FeatureSegment.priority.
55-
/// </summary>
56-
public bool IsHigherPriority(FeatureStateModel other)
57-
{
58-
if (this.FeatureSegment == null || other.FeatureSegment == null)
59-
{
60-
return this.FeatureSegment != null && other.FeatureSegment == null;
61-
}
62-
63-
return this.FeatureSegment.Priority < other.FeatureSegment.Priority;
64-
}
6526
[OnSerialized()]
6627
private void ValidatePercentageAllocations(StreamingContext _)
6728
{
Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,15 @@
1-
using FlagsmithEngine.Trait.Models;
21
using System;
32
using System.Collections.Generic;
4-
using System.Text;
53
using Newtonsoft.Json;
64
using FlagsmithEngine.Feature.Models;
7-
using System.Linq;
85

96
namespace FlagsmithEngine.Identity.Models
107
{
118
public class IdentityModel
129
{
13-
[JsonProperty("identity_uuid")]
14-
public string IdentityUUID { get; set; } = Guid.NewGuid().ToString();
1510
[JsonProperty("identifier")]
1611
public string Identifier { get; set; }
17-
[JsonProperty("environment_api_key")]
18-
public string EnvironmentApiKey { get; set; }
19-
[JsonProperty("created_date")]
20-
public DateTime CreatedDate { get; set; }
21-
[JsonProperty("identity_traits")]
22-
public List<TraitModel> IdentityTraits { get; set; }
2312
[JsonProperty("identity_features")]
2413
public IdentityFeaturesList IdentityFeatures { get; set; }
25-
[JsonProperty("django_id")]
26-
public int? DjangoId { get; set; }
27-
public string CompositeKey => GenerateCompositeKey(EnvironmentApiKey, Identifier);
28-
29-
public string GenerateCompositeKey(string envKey, string identifier) => $"{envKey}_{identifier}";
30-
public void UpdateTraits(List<TraitModel> traits)
31-
{
32-
var existingModels = IdentityTraits?.Count > 0 ? IdentityTraits.ToDictionary(x => x.TraitKey) : new Dictionary<string, TraitModel>();
33-
traits.ForEach(trait =>
34-
{
35-
if (trait.TraitValue is null)
36-
existingModels.Remove(trait.TraitKey);
37-
else
38-
existingModels[trait.TraitKey] = trait;
39-
});
40-
IdentityTraits = existingModels.Values.ToList();
41-
}
4214
}
4315
}

Flagsmith.Engine/Response/Response.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

Flagsmith.Engine/Segment/Evaluator.cs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using FlagsmithEngine.Environment.Models;
2-
using FlagsmithEngine.Identity.Models;
3-
using FlagsmithEngine.Segment.Models;
4-
using FlagsmithEngine.Trait.Models;
1+
using FlagsmithEngine.Segment.Models;
52
using FlagsmithEngine.Utils;
63
using Newtonsoft.Json;
74
using Newtonsoft.Json.Linq;
@@ -276,42 +273,6 @@ private static FlagResult<FeatureMetadataT> GetFlagResult<_, FeatureMetadataT>(E
276273

277274
public static class Evaluator
278275
{
279-
public static Hashing Hashing = new Hashing();
280-
281-
public static bool EvaluateIdentityInSegment(IdentityModel identity, SegmentModel segment, List<TraitModel> overrideTraits)
282-
{
283-
var traits = overrideTraits?.Any() == true ? overrideTraits : identity.IdentityTraits;
284-
var identityHashKey = identity.DjangoId == null ? identity.CompositeKey : identity.DjangoId.ToString();
285-
return segment.Rules?.Any() == true && segment.Rules.All(rule => TraitsMatchSegmentRule(traits, rule, segment.Id.ToString(), identityHashKey));
286-
}
287-
288-
static bool TraitsMatchSegmentRule(List<TraitModel> identityTraits, SegmentRuleModel rule, string segmentId, string identityId)
289-
{
290-
var matchesConditions = !rule.Conditions.Any() || rule.MatchingFunction(rule.Conditions.Select(c =>
291-
TraitsMatchSegmentCondition(identityTraits, c, segmentId, identityId)).ToList()
292-
);
293-
return matchesConditions && (rule.Rules?.All(r => TraitsMatchSegmentRule(identityTraits, r, segmentId, identityId)) ?? true);
294-
}
295-
296-
static bool TraitsMatchSegmentCondition(List<TraitModel> identityTraits, SegmentConditionModel condition, string segmentId, string identityId)
297-
{
298-
if (condition.Operator == Constants.PercentageSplit)
299-
return Hashing.GetHashedPercentageForObjectIds(new List<string>() { segmentId, identityId }) <= float.Parse(condition.Value);
300-
301-
var trait = identityTraits?.FirstOrDefault(t => t.TraitKey == condition.Property);
302-
303-
if (condition.Operator == Constants.IsSet)
304-
{
305-
return trait != null;
306-
}
307-
else if (condition.Operator == Constants.IsNotSet)
308-
{
309-
return trait == null;
310-
}
311-
312-
return trait != null && MatchesTraitValue(trait.TraitValue, condition);
313-
}
314-
315276
public static bool MatchesTraitValue(object traitValue, SegmentConditionModel condition)
316277
{
317278
var exceptionOperatorMethods = new Dictionary<string, string>()
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using System;
21
using System.Collections.Generic;
3-
using System.Linq;
42
using Newtonsoft.Json;
3+
54
namespace FlagsmithEngine.Segment.Models
65
{
76
public class SegmentRuleModel
@@ -12,16 +11,5 @@ public class SegmentRuleModel
1211
public List<SegmentRuleModel> Rules { get; set; }
1312
[JsonProperty("conditions")]
1413
public List<SegmentConditionModel> Conditions { get; set; } = new List<SegmentConditionModel>();
15-
16-
public bool MatchingFunction(List<bool> list)
17-
{
18-
switch (Type)
19-
{
20-
case Constants.AllRule: return list.All(x => x);
21-
case Constants.AnyRule: return list.Any(x => x);
22-
case Constants.NoneRule: return !list.Any(x => x);
23-
}
24-
throw new Exception("Rule Not Found");
25-
}
2614
}
2715
}

Flagsmith.Engine/Utils/Exceptions/Exceptions.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
using System;
42

53
namespace FlagsmithEngine.Exceptions
64
{
7-
public class FeatureStateNotFound : Exception
8-
{
9-
//Overriding the Message property
10-
public override string Message
11-
{
12-
get
13-
{
14-
return "Feature State not found.";
15-
}
16-
}
17-
}
185
public class DuplicateFeatureState : Exception
196
{
207
}

Flagsmith.EngineTest/Unit/Features/FeatureStateModelTest.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)