Skip to content

Commit f8a9d93

Browse files
committed
Removed properties if nil in sender
1 parent 8e03763 commit f8a9d93

4 files changed

Lines changed: 32 additions & 22 deletions

File tree

lib/splitclient-rb/cache/senders/impressions_formatter.rb

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,30 @@ def feature_impressions(filtered_impressions, feature)
3636
end
3737

3838
def current_impressions(feature_impressions)
39+
formatted = []
3940
feature_impressions.map do |impression|
40-
{
41-
k: impression[:i][:k],
42-
t: impression[:i][:t],
43-
m: impression[:i][:m],
44-
b: impression[:i][:b],
45-
r: impression[:i][:r],
46-
c: impression[:i][:c],
47-
pt: impression[:i][:pt],
48-
properties: impression[:i][:properties].to_json.to_s
49-
}
41+
if impression[:i][:properties].nil?
42+
impression = {
43+
k: impression[:i][:k],
44+
t: impression[:i][:t],
45+
m: impression[:i][:m],
46+
b: impression[:i][:b],
47+
r: impression[:i][:r],
48+
c: impression[:i][:c],
49+
pt: impression[:i][:pt]
50+
}
51+
else
52+
impression = {
53+
k: impression[:i][:k],
54+
t: impression[:i][:t],
55+
m: impression[:i][:m],
56+
b: impression[:i][:b],
57+
r: impression[:i][:r],
58+
c: impression[:i][:c],
59+
pt: impression[:i][:pt],
60+
properties: impression[:i][:properties].to_json.to_s
61+
}
62+
end
5063
end
5164
end
5265

lib/splitclient-rb/engine/common/impressions_manager.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def initialize(config,
1818
@unique_keys_tracker = unique_keys_tracker
1919
end
2020

21-
def build_impression(matching_key, bucketing_key, split_name, treatment_data, impressions_disabled, params = {}, properties = nil)
21+
def build_impression(matching_key, bucketing_key, split_name, treatment_data, impressions_disabled, params = {},
22+
properties = nil)
2223
impression_data = impression_data(matching_key, bucketing_key, split_name, treatment_data, params[:time], properties)
2324
begin
2425
if @config.impressions_mode == :none || impressions_disabled
@@ -83,7 +84,8 @@ def record_stats(stats)
8384
end
8485

8586
# added param time for test
86-
def impression_data(matching_key, bucketing_key, split_name, treatment, time = nil, properties = nil)
87+
def impression_data(matching_key, bucketing_key, split_name, treatment, time = nil,
88+
properties = nil)
8789
{
8890
k: matching_key,
8991
b: bucketing_key,

spec/cache/senders/impressions_formatter_spec.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
b: 'foo1',
5959
r: 'custom_label1',
6060
c: 123_456,
61-
pt: nil,
62-
properties: "null" }]
61+
pt: nil}]
6362
},
6463
{
6564
f: :foo2,
@@ -69,8 +68,7 @@
6968
b: 'foo2',
7069
r: 'custom_label2',
7170
c: 123_499,
72-
pt: nil,
73-
properties: "null" }]
71+
pt: nil}]
7472
}])
7573
end
7674

@@ -89,8 +87,7 @@
8987
b: 'foo1',
9088
r: 'custom_label1',
9189
c: 123_456,
92-
pt: nil,
93-
properties: 'null'
90+
pt: nil
9491
}
9592
]
9693
)
@@ -104,8 +101,7 @@
104101
b: 'foo2',
105102
r: 'custom_label2',
106103
c: 123_499,
107-
pt: nil,
108-
properties: "null"
104+
pt: nil
109105
},
110106
{
111107
k: 'matching_key3',

spec/cache/senders/impressions_sender_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
b: 'foo1',
7676
r: 'custom_label1',
7777
c: 123_456,
78-
pt: nil,
79-
properties: "null"
78+
pt: nil
8079
}
8180
]
8281
},

0 commit comments

Comments
 (0)