Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Veronika Solovei committed Aug 7, 2020
1 parent 19cb9c4 commit 35ddd9c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ func createBidExtension(videoRequest *openrtb_ext.BidRequestVideo) ([]byte, erro
IncludeWinners: true,
IncludeBrandCategory: inclBrandCat,
DurationRangeSec: durationRangeSec,
IncludeBidderKeys: true,
}

vastXml := openrtb_ext.ExtRequestPrebidCacheVAST{}
Expand Down
4 changes: 2 additions & 2 deletions exchange/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (a *auction) setRoundedPrices(priceGranularity openrtb_ext.PriceGranularity
a.roundedPrices = roundedPrices
}

func (a *auction) doCache(ctx context.Context, cache prebid_cache_client.Client, targData *targetData, bidRequest *openrtb.BidRequest, ttlBuffer int64, defaultTTLs *config.DefaultTTLs, bidCategory map[string]string, debugLog *DebugLog, isVideo bool) []error {
func (a *auction) doCache(ctx context.Context, cache prebid_cache_client.Client, targData *targetData, bidRequest *openrtb.BidRequest, ttlBuffer int64, defaultTTLs *config.DefaultTTLs, bidCategory map[string]string, debugLog *DebugLog) []error {
var bids, vast, includeBidderKeys, includeWinners bool = targData.includeCacheBids, targData.includeCacheVast, targData.includeBidderKeys, targData.includeWinners
if !((bids || vast) && (includeBidderKeys || includeWinners)) {
return nil
Expand Down Expand Up @@ -123,7 +123,7 @@ func (a *auction) doCache(ctx context.Context, cache prebid_cache_client.Client,
for _, topBidsPerImp := range a.winningBidsByBidder {
for _, topBidPerBidder := range topBidsPerImp {
impID := topBidPerBidder.bid.ImpID
isOverallWinner := a.winningBids[impID] == topBidPerBidder || isVideo
isOverallWinner := a.winningBids[impID] == topBidPerBidder
if !includeBidderKeys && !isOverallWinner {
continue
}
Expand Down
5 changes: 2 additions & 3 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,11 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque
}
}

isVideo := labels.RType == pbsmetrics.ReqTypeVideo
cacheErrs := auc.doCache(ctx, e.cache, targData, bidRequest, 60, &e.defaultTTLs, bidCategory, debugLog, isVideo)
cacheErrs := auc.doCache(ctx, e.cache, targData, bidRequest, 60, &e.defaultTTLs, bidCategory, debugLog)
if len(cacheErrs) > 0 {
errs = append(errs, cacheErrs...)
}
targData.setTargeting(auc, bidRequest.App != nil, bidCategory, isVideo)
targData.setTargeting(auc, bidRequest.App != nil, bidCategory)

// Ensure caching errors are added if the bid response ext has already been created
if bidResponseExt != nil && len(cacheErrs) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions exchange/targeting.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type targetData struct {
// The one exception is the `hb_cache_id` key. Since our APIs explicitly document cache keys to be on a "best effort" basis,
// it's ok if those stay in the auction. For now, this method implements a very naive cache strategy.
// In the future, we should implement a more clever retry & backoff strategy to balance the success rate & performance.
func (targData *targetData) setTargeting(auc *auction, isApp bool, categoryMapping map[string]string, isVideo bool) {
func (targData *targetData) setTargeting(auc *auction, isApp bool, categoryMapping map[string]string) {
for impId, topBidsPerImp := range auc.winningBidsByBidder {
overallWinner := auc.winningBids[impId]
for bidderName, topBidPerBidder := range topBidsPerImp {
isOverallWinner := overallWinner == topBidPerBidder || isVideo
isOverallWinner := overallWinner == topBidPerBidder

targets := make(map[string]string, 10)
if cpm, ok := auc.roundedPrices[topBidPerBidder]; ok {
Expand Down

0 comments on commit 35ddd9c

Please sign in to comment.