@@ -95,10 +95,23 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
95
95
} ) ;
96
96
97
97
let mut units: Vec < UnitByPrice > = eligible
98
+ // filter ad_units by whitelisted type, map then to UnitByPrice and flat_map them for each campaing
98
99
. 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 {
102
115
unit : ad_unit. clone ( ) ,
103
116
channel_id : campaign. id . clone ( ) ,
104
117
validators : campaign. spec . validators . clone ( ) ,
@@ -107,32 +120,16 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
107
120
. or ( campaign. spec . min_targeting_score )
108
121
. unwrap_or_else ( || 0 . into ( ) ) ,
109
122
min_per_impression : campaign. spec . min_per_impression . clone ( ) ,
110
- } ;
111
-
112
- units. push ( unit) ;
113
- }
114
-
115
- units
123
+ } )
116
124
} )
117
125
. collect ( ) ;
118
126
119
127
// Sort
120
128
units. sort_by ( |b, a| a. min_per_impression . cmp ( & b. min_per_impression ) ) ;
129
+ // Top units
121
130
units. truncate ( options. top_by_price ) ;
122
131
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
-
134
132
let mut by_score: Vec < Unit > = units
135
- . collect :: < Vec < UnitByPrice > > ( )
136
133
. into_iter ( )
137
134
. filter_map ( |by_price| {
138
135
let targeting_score =
0 commit comments