Skip to content
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

only do video caching if we don't already have a videoCacheKey #2143

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,32 @@ function addBidToAuction(auctionInstance, bidResponse) {
}

// Video bids may fail if the cache is down, or there's trouble on the network.
function tryAddVideoBid(auctionInstance, bidResponse, bidRequest, vastUrl) {
function tryAddVideoBid(auctionInstance, bidResponse, bidRequest) {
let willAdd = false;
if (config.getConfig('cache.url')) {
store([bidResponse], function(error, cacheIds) {
if (error) {
utils.logWarn(`Failed to save to the video cache: ${error}. Video bid must be discarded.`);

doCallbacksIfTimedout(auctionInstance, bidResponse);
} else {
bidResponse.videoCacheKey = cacheIds[0].uuid;
if (!vastUrl) {
bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey);
if (!bidResponse.videoCacheKey) {
willAdd = true;
store([bidResponse], function (error, cacheIds) {
if (error) {
utils.logWarn(`Failed to save to the video cache: ${error}. Video bid must be discarded.`);

doCallbacksIfTimedout(auctionInstance, bidResponse);
} else {
bidResponse.videoCacheKey = cacheIds[0].uuid;
if (!bidResponse.vastUrl) {
bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey);
}
// only set this prop after the bid has been cached to avoid early ending auction early in bidsBackAll
bidRequest.doneCbCallCount += 1;
addBidToAuction(auctionInstance, bidResponse);
auctionInstance.bidsBackAll();
}
// only set this prop after the bid has been cached to avoid early ending auction early in bidsBackAll
bidRequest.doneCbCallCount += 1;
addBidToAuction(auctionInstance, bidResponse);
auctionInstance.bidsBackAll();
}
});
} else {
});
} else if (!bidResponse.vastUrl) {
bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not need line 249. When videoCacheKey exists, publisher is not using cache.url, publisher should use either Prebid Server cache with cacheMarkup (videoCacheKey = cache_id, vastUrl = cache_url) or its own cache server (videoCacheKey = imp_id or anything client side adapter wants, vastUrl = creative_depot_url or anything client side adapter wants). And getCacheUrl method is using cache.url to build the Url.

Copy link
Collaborator Author

@snapwich snapwich Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we're not using this line (because we return vastUrl with videoCacheKey), but I'm not sure if other's might use it. Is there no scenario where an adapter would return the videoCacheKey but expect that key to work against the url set with cache.url?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if that scenario is not possible, then this line should probably be substituted with some kind of errors or warnings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we can throw errors or warnings here. videoCacheKey and vastUrl should be well defined in all cache scenarios.

}
}
if (!willAdd) {
addBidToAuction(auctionInstance, bidResponse);
}
}
Expand All @@ -256,7 +263,7 @@ export const addBidResponse = createHook('asyncSeries', function(adUnitCode, bid
let bidResponse = getPreparedBidForAuction({adUnitCode, bid, bidRequest, auctionId});

if (bidResponse.mediaType === 'video') {
tryAddVideoBid(auctionInstance, bidResponse, bidRequest, bid.vastUrl);
tryAddVideoBid(auctionInstance, bidResponse, bidRequest);
} else {
addBidToAuction(auctionInstance, bidResponse);
}
Expand Down