Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Delaying ref headers fetch until after startup #14620

Merged
merged 1 commit into from
Jul 24, 2018

Conversation

ryanml
Copy link
Contributor

@ryanml ryanml commented Jul 1, 2018

Fixes #14615

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed. (Ask a Brave employee to help if you cannot access this document.)

Test Plan:

  1. Create empty profile folder
  2. Create a file called promoCode in the profile folder with a test promo code, such as kam253
  3. Run Brave with LEDGER_VERBOSE=true and LEDGER_ENVIRONMENT=staging
  4. Confirm promotion code is read after 50 - 70 seconds (you should see call in the terminal)
  5. Make sure that promoCode file is deleted when using real promo code

Reviewer Checklist:

  • Request a security/privacy review as needed if one was not already requested.

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

// Delay should not occur after client boot has occured
const delay = (startupFetchDelay && !bootP) ? startupFetchDelay : 0

setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to track timeout and clear it before we add a new one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++

@ryanml ryanml force-pushed the fix-14615 branch 2 times, most recently from 1d5945f to 88a876e Compare July 1, 2018 23:26
@ryanml ryanml requested review from bbondy and NejcZdovc July 2, 2018 04:06
@NejcZdovc
Copy link
Contributor

@bbondy in this PR we are delaying ref request, but we are not delaying initial referral code read (IO). Would you like to delay this as well?

@NejcZdovc
Copy link
Contributor

@ryanml let's defer this read as well https://github.com/brave/browser-laptop/blob/master/app/browser/api/ledger.js?utf8=%E2%9C%93#L2346

@ryanml
Copy link
Contributor Author

ryanml commented Jul 7, 2018

@NejcZdovc in the current flow, delaying the promocode read on startup in turn will delay the call to fetchReferralHeaders that was occuring on startup, so I was able to condense the two schedules.

cc: @bbondy

@NejcZdovc
Copy link
Contributor

@ryanml please add auto-closing tag


promoCodeReadTimeoutId = setTimeout(() => {
module.exports.firstRunPromoCode()
}, ledgerUtil.milliseconds.minute)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be random for example 50s to 70s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
fetchReferralHeaders()
})
schedulePromoCodeRead()
} else {
fetchReferralHeaders()
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be delayed as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now delayed as well

@ryanml
Copy link
Contributor Author

ryanml commented Jul 12, 2018

@NejcZdovc changes addressed, ready for review

}

promoRefFetchTimeoutId = setTimeout(() => {
if (updateState.getUpdateProp(state, 'referralDownloadId') == null) {
Copy link
Contributor

@NejcZdovc NejcZdovc Jul 12, 2018

Choose a reason for hiding this comment

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

state in this case could be already outdated. You have up to 70s old state inside

Copy link
Contributor Author

Choose a reason for hiding this comment

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

App action has been created to remedy this, a fresh state will be used in these actions now.

@NejcZdovc
Copy link
Contributor

@ryanml please add test plan

@ryanml
Copy link
Contributor Author

ryanml commented Jul 15, 2018

@jasonrsadler rebased

Copy link
Contributor

@jasonrsadler jasonrsadler left a comment

Choose a reason for hiding this comment

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

Left one performance related note. Also, when running through the test plan above I get a 400 on the promo PUT. Maybe I'm doing something wrong?

fetchReferralHeaders()
}
// Schedule promo run and referral header fetch
schedulePromoRefFetch(state)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should move this call to the APP_INITIALIZED hook. in here:
https://github.com/brave/browser-laptop/blob/master/app/browser/reducers/ledgerReducer.js#L613
This gets called after most of the browser startup work and ledger.initialize and could save us a little bit on startup :) wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasonrsadler done. Also I can confirm that I am receiving 400 for the promo PUT using the test code on master.

Copy link
Contributor

@jasonrsadler jasonrsadler left a comment

Choose a reason for hiding this comment

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

-nit- When run with LEDGER_ENVIRONMENT=staging and verbose, gives a 500: Referral check was not successful [object Object]. I think we should check for body.message and display that so we have reason. Also, in DM do we have a working example of success?

@ryanml
Copy link
Contributor Author

ryanml commented Jul 18, 2018

@jasonrsadler am receiving a 400 on promo PUT as well on master, still see what's going on with things

@NejcZdovc

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

Test plan is not working for me, promoCode was not deleted. There were no request tot the server

@ryanml
Copy link
Contributor Author

ryanml commented Jul 19, 2018

Further inspecting the 400 that occurs on PUT to /promo/initialize/nonua, I am seeing that referralApi (even when running non-staging) is always an empty string. The response from the endpoint is:

"child \"api_key\" fails because [\"api_key\" is required]"

The referralApi key should either be extracted from the buildConfig (you would need to package) or provided via LEDGER_REFERRAL_API_KEY so this is probably why we are running in to issues.

This causes the chain reaction and causes the other 500 onReferralInit

cc: @NejcZdovc @jasonrsadler

@NejcZdovc
Copy link
Contributor

NejcZdovc commented Jul 20, 2018

updated test plan to the real promoCode key, so 500 should go away

@ryanml ryanml dismissed stale reviews from jasonrsadler and NejcZdovc July 24, 2018 02:19

promo code was faulty

@ryanml ryanml requested review from NejcZdovc and jasonrsadler July 24, 2018 02:19
Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

++

@NejcZdovc NejcZdovc merged commit 2483444 into brave:master Jul 24, 2018
NejcZdovc added a commit that referenced this pull request Jul 24, 2018
Delaying ref headers fetch until after startup
NejcZdovc added a commit that referenced this pull request Jul 24, 2018
Delaying ref headers fetch until after startup
@NejcZdovc
Copy link
Contributor

master 2483444
0.24 ed46f98
0.23 bc030f6

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants