Skip to content

Commit 821b28a

Browse files
authored
Merge branch 'dev' into 158-fix-validator-worker
2 parents ca161f1 + 87877fb commit 821b28a

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

adview-manager/src/lib.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,23 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
9595
});
9696

9797
let mut units: Vec<UnitByPrice> = eligible
98+
// filter ad_units by whitelisted type, map then to UnitByPrice and flat_map them for each campaing
9899
.flat_map(|campaign| {
99-
let mut units = vec![];
100-
for ad_unit in campaign.spec.ad_units.iter() {
101-
let unit = UnitByPrice {
100+
campaign
101+
.spec
102+
.ad_units
103+
.iter()
104+
.filter(|unit| {
105+
options
106+
.whitelisted_type
107+
.as_ref()
108+
.map(|whitelisted_type| {
109+
whitelisted_type != &unit.ad_type
110+
&& !(options.disabled_video && is_video(&unit))
111+
})
112+
.unwrap_or(false)
113+
})
114+
.map(move |ad_unit| UnitByPrice {
102115
unit: ad_unit.clone(),
103116
channel_id: campaign.id.clone(),
104117
validators: campaign.spec.validators.clone(),
@@ -107,32 +120,16 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
107120
.or(campaign.spec.min_targeting_score)
108121
.unwrap_or_else(|| 0.into()),
109122
min_per_impression: campaign.spec.min_per_impression.clone(),
110-
};
111-
112-
units.push(unit);
113-
}
114-
115-
units
123+
})
116124
})
117125
.collect();
118126

119127
// Sort
120128
units.sort_by(|b, a| a.min_per_impression.cmp(&b.min_per_impression));
129+
// Top units
121130
units.truncate(options.top_by_price);
122131

123-
let units = units.into_iter().filter(|unit| {
124-
options
125-
.whitelisted_type
126-
.as_ref()
127-
.map(|whitelisted_type| {
128-
whitelisted_type != &unit.unit.ad_type
129-
&& !(options.disabled_video && is_video(&unit.unit))
130-
})
131-
.unwrap_or(false)
132-
});
133-
134132
let mut by_score: Vec<Unit> = units
135-
.collect::<Vec<UnitByPrice>>()
136133
.into_iter()
137134
.filter_map(|by_price| {
138135
let targeting_score =

0 commit comments

Comments
 (0)