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

Over promotions #6403

Merged
merged 2 commits into from
Aug 13, 2020
Merged

Over promotions #6403

merged 2 commits into from
Aug 13, 2020

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented Aug 12, 2020

Resolves brave/brave-browser#11170

Submitter Checklist:

Test Plan:

  • N/A

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@NejcZdovc NejcZdovc added this to the 1.14.x - Nightly milestone Aug 12, 2020
@NejcZdovc NejcZdovc requested a review from a team August 12, 2020 07:40
@NejcZdovc NejcZdovc self-assigned this Aug 12, 2020
@NejcZdovc NejcZdovc requested review from emerick and zenparsing and removed request for a team August 12, 2020 07:40
@NejcZdovc NejcZdovc force-pushed the over-promotions branch 2 times, most recently from d71dce3 to 5be81bf Compare August 12, 2020 09:14
}

found = false;
for (const auto& item : list) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another option would be something like:

bool found = std::any_of(list.begin(), list.end(), [&promotion](auto& item) {
  item->id == promotion.second->id;
});

But haven't we already erased all entries in promotions that have a matching id (on line 255)? Is this search required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it's needed. We only erased promotions that we received from api and we have it in db. What we are doing here is going through active promotions that we have in db and if we don't find them in api we mark them as over

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking this through...

The loop starting on line 21 goes through all entries in list and removes the corresponding entry in promotions, if there is one. So after the loop completes, all entries in list have been removed from promotions, and promotions only contains entries that do not have a matching entry in list. Am I missing something?

Another way to simplify things (while avoiding a nested loop) might be to not erase from promotions, and instead populate an std::set with the ids from list, and then check that set in this loop over promotions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is correct. Use case is like this. Server serves promotion and we put it in db. Promotion has status active. User doesn't claim it. Then this promotion is removed from the server. We need to remove all promotions from db that has status active, but don't have corresponding promotion from server response

Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

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

LGTM

@NejcZdovc NejcZdovc requested a review from deeppandya August 13, 2020 06:11
Copy link
Contributor

@deeppandya deeppandya left a comment

Choose a reason for hiding this comment

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

I don't know the context of the issue here but Android code changes look good to me.

@NejcZdovc NejcZdovc merged commit ed12438 into master Aug 13, 2020
@NejcZdovc NejcZdovc deleted the over-promotions branch August 13, 2020 07:56
NejcZdovc added a commit that referenced this pull request Aug 14, 2020
NejcZdovc added a commit that referenced this pull request Aug 17, 2020
NejcZdovc added a commit that referenced this pull request Aug 18, 2020
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.

[Desktop] Mark promotion as over if not in response
4 participants