Skip to content

Commit

Permalink
no longer attaching gpt slots to adUnits, which breaks utils.cloneJso…
Browse files Browse the repository at this point in the history
…n(adUnit) (#1676)
  • Loading branch information
harpere authored and snapwich committed Oct 12, 2017
1 parent a907a4a commit f40f0e3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modules/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
utils.logWarn('no valid adUnits found, not loading ' + MODULE_NAME);
}

// store gpt slots in a more performant hash lookup by elementId (adUnit code)
var gptSlotCache = {};
// put adUnits in a more performant hash lookup by code.
var adUnitsCache = adUnits.reduce(function (cache, adUnit) {
if (adUnit.code && adUnit.bids) {
Expand Down Expand Up @@ -72,7 +74,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
const adUnit = adUnitsCache[elemId];

if (adUnit) {
adUnit._gptSlot = gptSlot;
gptSlotCache[elemId] = gptSlot; // store by elementId
adUnit.sizes = adUnit.sizes || mapGptSlotSizes(gptSlot.getSizes());
adUnits.push(adUnit);
gptSlots.splice(i, 1);
Expand Down Expand Up @@ -141,7 +143,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync();
fGptRefresh.apply(pads(), [
adUnits.map(function (adUnit) {
return adUnit._gptSlot;
return gptSlotCache[adUnit.code];
})
]);
}
Expand All @@ -157,7 +159,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
// get already displayed adUnits from aGptSlots if provided, else all defined gptSlots
aGptSlots = defaultSlots(aGptSlots);
var adUnits = pickAdUnits(/* mutated: */ aGptSlots).filter(function (adUnit) {
return adUnit._gptSlot._displayed;
return gptSlotCache[adUnit.code]._displayed;
});

if (aGptSlots.length) {
Expand All @@ -171,7 +173,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync();
fGptRefresh.apply(pads(), [
adUnits.map(function (adUnit) {
return adUnit._gptSlot
return gptSlotCache[adUnit.code];
}),
options
]);
Expand Down

0 comments on commit f40f0e3

Please sign in to comment.