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

Advanced Size Mapping - Code Refactoring. #5487

Merged
merged 4 commits into from
Jul 23, 2020
Merged

Advanced Size Mapping - Code Refactoring. #5487

merged 4 commits into from
Jul 23, 2020

Conversation

Fawke
Copy link
Contributor

@Fawke Fawke commented Jul 13, 2020

Type of change

  • Bugfix
  • Refactoring (no functional changes, no api changes)

Description of change

  • checkAdUnitSetup in src/prebid.js has been refactored to not mutate the adUnit object. Similarly, helper functions such as validateBannerMediaType, validateVideoMediaType and validateNativeMediaType have been refactor to avoid mutation of the adUnit object.

  • A similar function, checkAdUnitSetupHook in modules/sizeMappingV2.js is also refactored to avoid mutation of adUnit object.

  • sizeConfig validation checks has been moved to a single function, validateSizeConfig which returns a boolean, and does not mutate the adUnit object.

  • Re-write some of the comments in modules/sizeMappingV2.js to make them more descriptive.

  • Re-write / shorten / remove some log messages in modules/sizeMappingV2.js

  • A test has been skipped in pubCommonId_spec.js file. The test is failing, due to reasons not related to this change, as far as I know. I'll request someone from pubCommonId to take a look.

  • Resolves Advanced Size Mapping Module bug empties config on refresh #5458. This bug was caused because we were mutating the adUnit object inside the checkAdUnitSetupHook function in modules/sizeMappingV2.js file.

@Fawke Fawke changed the title Advanced Size Mapping - Code Refactoring. Advance Size Mapping - Code Refactoring. Jul 13, 2020
@lgtm-com
Copy link

lgtm-com bot commented Jul 13, 2020

This pull request introduces 1 alert when merging d6004ba into a2ec9c2 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@@ -448,6 +461,8 @@ $$PREBID_GLOBAL$$.requestBids = hook('async', function ({ bidsBackHandler, timeo

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

adUnits = checkAdUnitSetup(adUnits);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving call to checkAdUnitSetup before we calculate the value of adUnitCodes. This is required because if some adUnit is removed in the function ,checkAdUnitSetup, then, the code below will incorrectly include the deactivated adUnit's code in the adUnitCodes variable.

@Fawke Fawke changed the title Advance Size Mapping - Code Refactoring. Advanced Size Mapping - Code Refactoring. Jul 13, 2020
@benjaminclot
Copy link
Contributor

@Fawke why do you use "caching" (cacheHits)? Won't that cause a problem when somebody triggers an ad refresh after a window resize?

@Fawke
Copy link
Contributor Author

Fawke commented Jul 14, 2020

@Fawke why do you use "caching" (cacheHits)? Won't that cause a problem when somebody triggers an ad refresh after a window resize?

@benjaminclot Caching is an internal implementation detail which should not effect page refreshes after a window resize. To give you an overview, caching stores a data structure which is mapped to an auctionId.

[{
  'auction-id-1': {
    adUnits: [
      <<contains details about adunits after size mapping checks>>
    ],
    cacheHits:1
  }
}]

This is done because we don't want to do sizeMapping processing for each bidder separately. It's done for the first bidder, stored in the cache, the next bidder picks up the details from this object and we increment the cacheHits.

If you refresh the page, it'll be a new auction (a new call to requestBids), which won't read data from the old auction, but create a new object. So, I think, it should be fine.

@benjaminclot
Copy link
Contributor

@Fawke I was talking about the next call to pbjs.requestBids() but you're right, as long as the cache is linked to the auctionId, we'll be fine.

@Fawke Fawke requested review from bretg and robertrmartinez July 16, 2020 13:48
@bretg
Copy link
Collaborator

bretg commented Jul 16, 2020

@Fawke - any docs updates?

@Fawke
Copy link
Contributor Author

Fawke commented Jul 17, 2020

@bretg Not really, no changes to the API.

@bretg
Copy link
Collaborator

bretg commented Jul 17, 2020

Cool - with there aren't changes to the interface, I'll remove myself from the reviewers.

@bretg bretg removed their request for review July 17, 2020 17:45
@jsnellbaker jsnellbaker added needs 2nd review Core module updates require two approvals from the core team and removed needs review labels Jul 20, 2020
Copy link
Collaborator

@robertrmartinez robertrmartinez left a comment

Choose a reason for hiding this comment

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

looks good, just the question about the pubmatic skipped test.

native: 'active'
}
const propertyName = associatedProperty[mediaType];
const conditionalLogMessages = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 on the maps based off the mediaType, cool stuff

@@ -234,7 +234,7 @@ describe('Publisher Common ID', function () {
});
});

it('disable auto create', function() {
it.skip('disable auto create', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we skipping this?

Copy link
Contributor Author

@Fawke Fawke Jul 23, 2020

Choose a reason for hiding this comment

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

If we don't skip this test, this fails!

What I could gather from this is that the test that I have skipped, it disables autocreate of bid.crumbs.pubcid. Then, later, this configuration is not cleared which is leading to the test case, I mentioned above, to fail!

If I find time later, will try to dig deep to ascertain the cause of the failure, but for now, everything seems to be working fine, we can merge this!

@Fawke Fawke merged commit bf5c7c7 into master Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs 2nd review Core module updates require two approvals from the core team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Advanced Size Mapping Module bug empties config on refresh
5 participants