@@ -138,21 +138,26 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque
138
138
// Get currency rates conversions for the auction
139
139
conversions := e .currencyConverter .Rates ()
140
140
141
- adapterBids , adapterExtra := e .getAllBids (auctionCtx , cleanRequests , aliases , bidAdjustmentFactors , blabels , conversions )
142
- bidCategory , adapterBids , err := applyCategoryMapping (ctx , requestExt , adapterBids , * categoriesFetcher , targData )
143
- auc := newAuction (adapterBids , len (bidRequest .Imp ))
144
- if err != nil {
145
- return nil , fmt .Errorf ("Error in category mapping : %s" , err .Error ())
146
- }
141
+ adapterBids , adapterExtra , anyBidsReturned := e .getAllBids (auctionCtx , cleanRequests , aliases , bidAdjustmentFactors , blabels , conversions )
142
+
143
+ if anyBidsReturned {
144
+ bidCategory , adapterBids , err := applyCategoryMapping (ctx , requestExt , adapterBids , * categoriesFetcher , targData )
145
+ if err != nil {
146
+ return nil , fmt .Errorf ("Error in category mapping : %s" , err .Error ())
147
+ }
147
148
148
- if targData != nil && adapterBids != nil {
149
- auc .setRoundedPrices (targData .priceGranularity )
150
- cacheErrs := auc .doCache (ctx , e .cache , targData , bidRequest , 60 , & e .defaultTTLs , bidCategory )
151
- if len (cacheErrs ) > 0 {
152
- errs = append (errs , cacheErrs ... )
149
+ auc := newAuction (adapterBids , len (bidRequest .Imp ))
150
+
151
+ if targData != nil {
152
+ auc .setRoundedPrices (targData .priceGranularity )
153
+ cacheErrs := auc .doCache (ctx , e .cache , targData , bidRequest , 60 , & e .defaultTTLs , bidCategory )
154
+ if len (cacheErrs ) > 0 {
155
+ errs = append (errs , cacheErrs ... )
156
+ }
157
+ targData .setTargeting (auc , bidRequest .App != nil , bidCategory )
153
158
}
154
- targData .setTargeting (auc , bidRequest .App != nil , bidCategory )
155
159
}
160
+
156
161
// Build the response
157
162
return e .buildBidResponse (ctx , liveAdapters , adapterBids , bidRequest , resolvedRequest , adapterExtra , errs )
158
163
}
@@ -169,11 +174,12 @@ func (e *exchange) makeAuctionContext(ctx context.Context, needsCache bool) (auc
169
174
}
170
175
171
176
// This piece sends all the requests to the bidder adapters and gathers the results.
172
- func (e * exchange ) getAllBids (ctx context.Context , cleanRequests map [openrtb_ext.BidderName ]* openrtb.BidRequest , aliases map [string ]string , bidAdjustments map [string ]float64 , blabels map [openrtb_ext.BidderName ]* pbsmetrics.AdapterLabels , conversions currencies.Conversions ) (map [openrtb_ext.BidderName ]* pbsOrtbSeatBid , map [openrtb_ext.BidderName ]* seatResponseExtra ) {
177
+ func (e * exchange ) getAllBids (ctx context.Context , cleanRequests map [openrtb_ext.BidderName ]* openrtb.BidRequest , aliases map [string ]string , bidAdjustments map [string ]float64 , blabels map [openrtb_ext.BidderName ]* pbsmetrics.AdapterLabels , conversions currencies.Conversions ) (map [openrtb_ext.BidderName ]* pbsOrtbSeatBid , map [openrtb_ext.BidderName ]* seatResponseExtra , bool ) {
173
178
// Set up pointers to the bid results
174
179
adapterBids := make (map [openrtb_ext.BidderName ]* pbsOrtbSeatBid , len (cleanRequests ))
175
180
adapterExtra := make (map [openrtb_ext.BidderName ]* seatResponseExtra , len (cleanRequests ))
176
181
chBids := make (chan * bidResponseWrapper , len (cleanRequests ))
182
+ bidsFound := false
177
183
178
184
for bidderName , req := range cleanRequests {
179
185
// Here we actually call the adapters and collect the bids.
@@ -228,9 +234,13 @@ func (e *exchange) getAllBids(ctx context.Context, cleanRequests map[openrtb_ext
228
234
brw := <- chBids
229
235
adapterBids [brw .bidder ] = brw .adapterBids
230
236
adapterExtra [brw .bidder ] = brw .adapterExtra
237
+
238
+ if ! bidsFound && adapterBids [brw .bidder ] != nil && len (adapterBids [brw .bidder ].bids ) > 0 {
239
+ bidsFound = true
240
+ }
231
241
}
232
242
233
- return adapterBids , adapterExtra
243
+ return adapterBids , adapterExtra , bidsFound
234
244
}
235
245
236
246
func (e * exchange ) recoverSafely (inner func (openrtb_ext.BidderName , openrtb_ext.BidderName , * openrtb.BidRequest , * pbsmetrics.AdapterLabels , currencies.Conversions ), chBids chan * bidResponseWrapper ) func (openrtb_ext.BidderName , openrtb_ext.BidderName , * openrtb.BidRequest , * pbsmetrics.AdapterLabels , currencies.Conversions ) {
0 commit comments