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

Fix removeAdUnit #4053

Merged
merged 4 commits into from
Aug 9, 2019
Merged

Fix removeAdUnit #4053

merged 4 commits into from
Aug 9, 2019

Conversation

benjaminclot
Copy link
Contributor

Type of change

  • Bugfix

Description of change

When there are multiple adUnits with the same code, only one of them gets removed. This fixes that.

When there are multiple adUnits with the same code, only one of them gets removed. This fixes that.
@benjaminclot
Copy link
Contributor Author

All tests pass but CircleCI keeps returning timeouts :-/

@jsnellbaker jsnellbaker added needs review needs 2nd review Core module updates require two approvals from the core team labels Aug 2, 2019
Copy link
Contributor

@idettman idettman left a comment

Choose a reason for hiding this comment

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

I've reviewed and the code looks ok, but I'm unable to get the circleci tests to pass.

Can you try updating your branch with the latest from Prebid.js master, it may fix to the circleci failure.

@benjaminclot
Copy link
Contributor Author

@idettman The branch has been updated with master and there's still a timeout error.

Copy link
Contributor

@idettman idettman left a comment

Choose a reason for hiding this comment

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

LGTM

@snapwich snapwich self-assigned this Aug 7, 2019
Copy link
Collaborator

@snapwich snapwich left a comment

Choose a reason for hiding this comment

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

This is a bug. The original code should work except they're iterating over the object they're mutating. Your solution probably works but changes functionality a little bit (creates a new array reference). I'd rather the bug was fixed without changing the exposed API (even if slight, it has potential to break things).

In this case, the fix would be to iterate over the adUnit array backwards.

@idettman
Copy link
Contributor

idettman commented Aug 7, 2019

Nice catch @snapwich, so would the fix be something like this?

  adUnitCodes.forEach((adUnitCode) => {
    for (let i = $$PREBID_GLOBAL$$.adUnits.length - 1; i >= 0; i--) {
      if ($$PREBID_GLOBAL$$.adUnits[i].code === adUnitCode) {
        $$PREBID_GLOBAL$$.adUnits.splice(i, 1);
      }
    }
  })

@snapwich
Copy link
Collaborator

snapwich commented Aug 7, 2019

@idettman should be i >= 0, but other than that I think it's good.

@benjaminclot
Copy link
Contributor Author

@snapwich @idettman requested change has been committed

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.

LGTM

Copy link
Collaborator

@snapwich snapwich left a comment

Choose a reason for hiding this comment

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

LGTM

@snapwich snapwich merged commit 6fb6049 into prebid:master Aug 9, 2019
sa1omon pushed a commit to gamoshi/Prebid.js that referenced this pull request Nov 28, 2019
* Fix removeAdUnit

When there are multiple adUnits with the same code, only one of them gets removed. This fixes that.

* snapwich fix
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.

5 participants