-
Notifications
You must be signed in to change notification settings - Fork 972
Delaying ref headers fetch until after startup #14620
Conversation
app/browser/api/ledger.js
Outdated
// Delay should not occur after client boot has occured | ||
const delay = (startupFetchDelay && !bootP) ? startupFetchDelay : 0 | ||
|
||
setTimeout(() => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
1d5945f
to
88a876e
Compare
@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? |
@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 |
0fd12d4
to
32adb33
Compare
@NejcZdovc in the current flow, delaying the promocode read on startup in turn will delay the call to cc: @bbondy |
@ryanml please add auto-closing tag |
app/browser/api/ledger.js
Outdated
|
||
promoCodeReadTimeoutId = setTimeout(() => { | ||
module.exports.firstRunPromoCode() | ||
}, ledgerUtil.milliseconds.minute) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
app/browser/api/ledger.js
Outdated
} | ||
fetchReferralHeaders() | ||
}) | ||
schedulePromoCodeRead() | ||
} else { | ||
fetchReferralHeaders() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@NejcZdovc changes addressed, ready for review |
app/browser/api/ledger.js
Outdated
} | ||
|
||
promoRefFetchTimeoutId = setTimeout(() => { | ||
if (updateState.getUpdateProp(state, 'referralDownloadId') == null) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@ryanml please add test plan |
@jasonrsadler rebased |
There was a problem hiding this 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?
app/browser/api/ledger.js
Outdated
fetchReferralHeaders() | ||
} | ||
// Schedule promo run and referral header fetch | ||
schedulePromoRefFetch(state) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
@jasonrsadler am receiving a 400 on promo PUT as well on master, still see what's going on with things |
There was a problem hiding this 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
Further inspecting the 400 that occurs on PUT to
The referralApi key should either be extracted from the buildConfig (you would need to package) or provided via This causes the chain reaction and causes the other 500 |
updated test plan to the real promoCode key, so 500 should go away |
promo code was faulty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
Delaying ref headers fetch until after startup
Delaying ref headers fetch until after startup
Fixes #14615
Submitter Checklist:
git rebase -i
to squash commits (if needed).Test Plan:
promoCode
in the profile folder with a test promo code, such askam253
LEDGER_VERBOSE=true and LEDGER_ENVIRONMENT=staging
promoCode
file is deleted when using real promo codeReviewer Checklist:
Tests