-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache validation fix #911
Cache validation fix #911
Changes from all commits
0b83c27
3e84ad8
043be36
6739537
e82b10e
abff28a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,21 +138,26 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque | |
// Get currency rates conversions for the auction | ||
conversions := e.currencyConverter.Rates() | ||
|
||
adapterBids, adapterExtra := e.getAllBids(auctionCtx, cleanRequests, aliases, bidAdjustmentFactors, blabels, conversions) | ||
bidCategory, adapterBids, err := applyCategoryMapping(ctx, requestExt, adapterBids, *categoriesFetcher, targData) | ||
auc := newAuction(adapterBids, len(bidRequest.Imp)) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error in category mapping : %s", err.Error()) | ||
} | ||
adapterBids, adapterExtra, anyBidsReturned := e.getAllBids(auctionCtx, cleanRequests, aliases, bidAdjustmentFactors, blabels, conversions) | ||
|
||
if anyBidsReturned { | ||
bidCategory, adapterBids, err := applyCategoryMapping(ctx, requestExt, adapterBids, *categoriesFetcher, targData) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally makes sense. Done. |
||
return nil, fmt.Errorf("Error in category mapping : %s", err.Error()) | ||
} | ||
|
||
if targData != nil && adapterBids != nil { | ||
auc.setRoundedPrices(targData.priceGranularity) | ||
cacheErrs := auc.doCache(ctx, e.cache, targData, bidRequest, 60, &e.defaultTTLs, bidCategory) | ||
if len(cacheErrs) > 0 { | ||
errs = append(errs, cacheErrs...) | ||
auc := newAuction(adapterBids, len(bidRequest.Imp)) | ||
|
||
if targData != nil { | ||
auc.setRoundedPrices(targData.priceGranularity) | ||
cacheErrs := auc.doCache(ctx, e.cache, targData, bidRequest, 60, &e.defaultTTLs, bidCategory) | ||
if len(cacheErrs) > 0 { | ||
errs = append(errs, cacheErrs...) | ||
} | ||
targData.setTargeting(auc, bidRequest.App != nil, bidCategory) | ||
} | ||
targData.setTargeting(auc, bidRequest.App != nil, bidCategory) | ||
} | ||
|
||
// Build the response | ||
return e.buildBidResponse(ctx, liveAdapters, adapterBids, bidRequest, resolvedRequest, adapterExtra, errs) | ||
} | ||
|
@@ -169,11 +174,12 @@ func (e *exchange) makeAuctionContext(ctx context.Context, needsCache bool) (auc | |
} | ||
|
||
// This piece sends all the requests to the bidder adapters and gathers the results. | ||
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) { | ||
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) { | ||
// Set up pointers to the bid results | ||
adapterBids := make(map[openrtb_ext.BidderName]*pbsOrtbSeatBid, len(cleanRequests)) | ||
adapterExtra := make(map[openrtb_ext.BidderName]*seatResponseExtra, len(cleanRequests)) | ||
chBids := make(chan *bidResponseWrapper, len(cleanRequests)) | ||
bidsFound := false | ||
|
||
for bidderName, req := range cleanRequests { | ||
// 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 | |
brw := <-chBids | ||
adapterBids[brw.bidder] = brw.adapterBids | ||
adapterExtra[brw.bidder] = brw.adapterExtra | ||
|
||
if !bidsFound && adapterBids[brw.bidder] != nil && len(adapterBids[brw.bidder].bids) > 0 { | ||
bidsFound = true | ||
} | ||
} | ||
|
||
return adapterBids, adapterExtra | ||
return adapterBids, adapterExtra, bidsFound | ||
} | ||
|
||
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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kalypsonika this is very, very minor but, just for the sake of saving memory in the heap and trying to declare as less local variables as possible, can we get rid of lines 406 and 419 and change the return statement in line 421?
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!