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

Filter bid arrays using adUnitsFilter function #750

Merged
merged 15 commits into from
Nov 11, 2016

Conversation

protonate
Copy link
Collaborator

Type of change

  • Bugfix

Description of change

The requested and received bid arrays must retain bid objects from multiple calls to pbjs .requestBids. However this causes unexpected behavior in the reporting APIs as bids from
previous auctions were returned. This PR addresses this by creating a pbjs._adUnitCodes primary
data structure to be used as a filter when Prebid needs only the current "auction". While not
ideal this allows us to retain bid data for in-flight calls to an ad server while also allowing
additional bid requests to be made without the introduction of Prebid Auction instances.

Closes #590

  • reset externalCallbacks.all.called
  • use adUnitsFilter to filter bid arrays to current auction

@protonate
Copy link
Collaborator Author

@dugwood you will notice here that I've reversed myself on an adUnitCodes data structure. It will be useful to define the filter for now until we've restructured how multiple bid requests are handled. Thanks for the idea.

@dugwood
Copy link
Contributor

dugwood commented Oct 28, 2016

@protonate yes, that's great I think :-) I've reviewed a bit your code, and there's a lot of changes! Wouldn't it be useful to set a big global object that would group all current global variables?

  $$PREBID_GLOBAL$$._bidsRequested = [];
  $$PREBID_GLOBAL$$._bidsReceived = [];
  $$PREBID_GLOBAL$$._adUnitCodes = [];
  $$PREBID_GLOBAL$$._winningBids = [];
  $$PREBID_GLOBAL$$._adsReceived = [];
  $$PREBID_GLOBAL$$._sendAllBids = false;

I'll try this code today, as I have issues with Rubicon and multiple sizes. Maybe that will fix it too. Rubicon team is working on the issue anyway.

@mkendall07
Copy link
Member

@protonate Looks like there is conflicts now. Please resolve thanks

@protonate protonate force-pushed the bugfix/callback-uses-placement-filter branch from f73f234 to 4e03174 Compare November 1, 2016 06:42
@protonate
Copy link
Collaborator Author

@mkendall07 conflicts fixed

@@ -38,6 +38,7 @@ var eventValidators = {

$$PREBID_GLOBAL$$._bidsRequested = [];
$$PREBID_GLOBAL$$._bidsReceived = [];
$$PREBID_GLOBAL$$._adUnitCodes = [];
Copy link
Member

Choose a reason for hiding this comment

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

this name isn't super intuitive. Maybe just add comment here on what this is.

utils.logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments);

if (!adUnits || adUnits.length === 0) {
utils.logMessage('No adUnits configured. No bids requested.');
if (typeof bidsBackHandler === objectType_function) {
bidmanager.addOneTimeCallback(bidsBackHandler, false);
}

Copy link
Member

Choose a reason for hiding this comment

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

extra line breaks.

}

// we will use adUnitCodes for filtering the current auction
$$PREBID_GLOBAL$$._adUnitCodes = adUnitCodes;
Copy link
Member

Choose a reason for hiding this comment

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

doesn't this clubber a current auction running codes since it's before if (auctionRunning) check?

@protonate protonate force-pushed the bugfix/callback-uses-placement-filter branch from 4e03174 to fa0feb4 Compare November 1, 2016 16:57
@protonate
Copy link
Collaborator Author

@mkendall07 note addressed

@protonate
Copy link
Collaborator Author

@mkendall07 ready for review

@protonate protonate force-pushed the bugfix/callback-uses-placement-filter branch from 0a37f14 to 1edc943 Compare November 7, 2016 03:09
@protonate
Copy link
Collaborator Author

This PR has been updated and is ready to test. The following changes have been made.

Applies the current adUnitCodes filter when calling reporting APIs getBidResponses, getAdserverTargeting.
Queues a bid request if a previous request is still running, closing over instance data.
Clears previous bids from placements included in current bid request (remove stale bids).

Note that if a placement is included in one request and a second request as well, and the second request is made before the first request has rendered an ad, the bids for the first request will be cleared and the renderAd function will throw an error as the bids cannot be found. However, the placement should be immediately filled with the results of the second request. The error is not caught so as to warn that a placement was overwritten, and care should be taken not to request bids for a placement with a request already in flight.

fixes #772
fixes #590

Copy link
Member

@mkendall07 mkendall07 left a comment

Choose a reason for hiding this comment

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

Just a few comments.

@@ -43,6 +43,7 @@ function getBidders(bid) {
function bidsBackAdUnit(adUnitCode) {
const requested = $$PREBID_GLOBAL$$._bidsRequested
.map(request => request.bids
.filter(adUnitsFilter.bind(this, $$PREBID_GLOBAL$$._adUnitCodes))
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for using bind here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's isn't needed here, only in places where the filter may be passed in rather than the current pbjs._adUnitCodes array. I'll remove from here and elsewhere where we can and have utils.adUnitsFilter check for an array passed in and if not found use ad unit codes defined on global.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually if we use .bind for processCallbacks to support a single ad unit code or all ad unit codes (for bidsBackAdUnit and bidsBackAll respectively) then we should use the same partial application pattern in all of these cases. This is probably preferable as the ad unit codes to use as a filter can be set as instance data on the requestBids function and we can remove the _adUnitCodes global property.

@@ -273,19 +278,26 @@ exports.executeCallback = function (timedOut) {
}
};

exports.externalCallbackReset = function () {
externalCallbacks.all.called = false;
Copy link
Member

Choose a reason for hiding this comment

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

externalCallbacks has evolved into complex object. Should we formalize this into int's own file / class constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like that idea.

@protonate
Copy link
Collaborator Author

@mkendall07 any changes needed to merge?

@mkendall07
Copy link
Member

Sorry @protonate I didn't get a chance to test this PR yet. I'll do that today and sans any issues we can merge it.

@mkendall07
Copy link
Member

Tested functionality, LGTM. Can merge after resolving conflicts.

protonate added 4 commits November 10, 2016 09:47
The requested and received bid arrays must retain bid objects from multiple calls to `pbjs
.requestBids`. However this causes unexpected behavior in the reporting APIs as bids from
previous auctions were returned. This PR addresses this by creating a `pbjs._adUnitCodes` primary
 data structure to be used as a filter when Prebid needs only the current "auction". While not
 ideal this allows us to retain bid data for in-flight calls to an ad server while also allowing
 additional bid requests to be made without the introduction of Prebid Auction instances.

 Closes #590

* reset externalCallbacks.all.called
* use adUnitsFilter to filter bid arrays to current auction
protonate added 11 commits November 10, 2016 09:47
Applies the filter when calling reporting APIs `getBidResponses`, `getAdserverTargeting`.
Queues a bid request if a previous request is still running, closing over instance data.
Clears previous bids from placements included in current bid request (remove stale bids).

Note that if a placement is included in one request and a second request as well, and the second request is made before the first request has rendered an ad, the bids for the first request will be cleared and the `renderAd` function will throw an error as the bids cannot be found. However, the placement should be immediately filled with the results of the second request. The error is not caught so as to warn that a placement was overwritten, and care should be taken not to request bids for a placement with a request already in flight.

fixes #772
fixes #590
@protonate protonate force-pushed the bugfix/callback-uses-placement-filter branch from e53f07a to 6d97e91 Compare November 10, 2016 17:52
@protonate
Copy link
Collaborator Author

@mkendall07 conflicts are resolved

@mkendall07 mkendall07 merged commit 16ea57c into master Nov 11, 2016
@mkendall07 mkendall07 deleted the bugfix/callback-uses-placement-filter branch November 11, 2016 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prebid 12 - pbjs.requestBids - returns all ads, not just ads in paths array.
3 participants