@@ -63,50 +63,50 @@ class DefaultDecisionService : OPTDecisionService {
6363 return variation
6464 }
6565
66- var bucketedVariation : Variation ?
6766 // ---- check if the user passes audience targeting before bucketing ----
68- if isInExperiment ( config: config, experiment: experiment, userId: userId, attributes: attributes) {
69- // bucket user into a variation
70- bucketedVariation = bucketer. bucketExperiment ( config: config, experiment: experiment, bucketingId: bucketingId)
71-
72- if let bucketedVariation = bucketedVariation {
67+ if isInExperiment ( config: config, experiment: experiment, userId: userId, attributes: attributes) , let bucketedVariation = bucketer. bucketExperiment ( config: config, experiment: experiment, bucketingId: bucketingId) {
7368 // save to user profile
74- self . saveProfile ( userId: userId, experimentId: experimentId, variationId: bucketedVariation. id)
75- }
69+ self . saveProfile ( userId: userId, experimentId: experimentId, variationId: bucketedVariation. id)
70+ return bucketedVariation
7671 } else {
7772 logger? . i ( . userNotInExperiment( userId, experiment. key) )
7873 }
7974
80- return bucketedVariation;
75+ return nil
8176 }
8277
8378 func isInExperiment( config: ProjectConfig , experiment: Experiment , userId: String , attributes: OptimizelyAttributes ) -> Bool {
84-
79+
80+ func innerEvaluate( conditions: ConditionHolder ) throws -> Bool {
81+ var result = false
82+ switch conditions {
83+ case . array( let arrConditions) :
84+ if arrConditions. count > 0 {
85+ result = try conditions. evaluate ( project: config. project, attributes: attributes)
86+ } else {
87+ // empty conditions (backward compatibility with "audienceIds" is ignored if exists even though empty
88+ result = true
89+ }
90+ case . leaf:
91+ result = try conditions. evaluate ( project: config. project, attributes: attributes)
92+ default :
93+ result = true
94+ }
95+ return result
96+ }
8597 var result = true // success as default (no condition, etc)
8698
8799 do {
88100 if let conditions = experiment. audienceConditions {
89- switch conditions {
90- case . array( let arrConditions) :
91- if arrConditions. count > 0 {
92- result = try conditions. evaluate ( project: config. project, attributes: attributes)
93- } else {
94- // empty conditions (backward compatibility with "audienceIds" is ignored if exists even though empty
95- result = true
96- }
97- case . leaf:
98- result = try conditions. evaluate ( project: config. project, attributes: attributes)
99- default :
100- result = true
101- }
101+ result = try innerEvaluate ( conditions: conditions)
102102 }
103103 // backward compatibility with audiencIds list
104104 else if experiment. audienceIds. count > 0 {
105105 var holder = [ ConditionHolder] ( )
106106 holder. append ( . logicalOp( . or) )
107- for id in experiment. audienceIds {
108- holder. append ( . leaf( . audienceId( id ) ) )
109- }
107+ experiment. audienceIds. forEach ( {
108+ holder. append ( . leaf( . audienceId( $0 ) ) )
109+ } )
110110
111111 result = try holder. evaluate ( project: config. project, attributes: attributes)
112112 }
0 commit comments