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

Commit

Permalink
Merge pull request #14621 from jasonrsadler/perf/#14616-ugp-boot-delay
Browse files Browse the repository at this point in the history
Moved UGP request delay up to 1 minute.
  • Loading branch information
NejcZdovc committed Jul 6, 2018
1 parent a0e52ed commit 0e87995
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
28 changes: 20 additions & 8 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1325,13 +1325,11 @@ const checkPromotions = () => {
}, random.randomInt({min: 20 * ledgerUtil.milliseconds.hour, max: 24 * ledgerUtil.milliseconds.hour}))
}

const enable = (state, paymentsEnabled) => {
if (paymentsEnabled) {
if (!getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) {
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true)
}
}
const runPromotionCheck = () => {
appActions.runPromotionCheck()
}

const onRunPromotionCheck = (state, paymentsEnabled) => {
if (paymentsEnabled === getSetting(settings.PAYMENTS_ENABLED)) {
// on start
if (togglePromotionTimeoutId) {
Expand All @@ -1340,7 +1338,10 @@ const enable = (state, paymentsEnabled) => {

togglePromotionTimeoutId = setTimeout(() => {
checkPromotions()
}, random.randomInt({min: 10 * ledgerUtil.milliseconds.second, max: 15 * ledgerUtil.milliseconds.second}))
}, process.env.LEDGER_ENVIRONMENT === 'staging'
? random.randomInt({min: 10 * ledgerUtil.milliseconds.second, max: 15 * ledgerUtil.milliseconds.second})
: random.randomInt({min: 45 * ledgerUtil.milliseconds.second, max: 60 * ledgerUtil.milliseconds.second})
)
} else if (paymentsEnabled) {
// toggle on
if (togglePromotionTimeoutId) {
Expand All @@ -1358,6 +1359,15 @@ const enable = (state, paymentsEnabled) => {
// toggle off
state = ledgerState.setPromotionProp(state, 'promotionStatus', null)
}
return state
}

const enable = (state, paymentsEnabled) => {
if (paymentsEnabled) {
if (!getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) {
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true)
}
}

if (synopsis) {
return updatePublisherInfo(state, null, true)
Expand Down Expand Up @@ -3343,7 +3353,9 @@ const getMethods = () => {
getPaymentInfo,
synopsisNormalizer,
cacheRuleSet,
disablePayments
disablePayments,
runPromotionCheck,
onRunPromotionCheck
}

let privateMethods = {}
Expand Down
10 changes: 10 additions & 0 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const windowConstants = require('../../../js/constants/windowConstants')
const settings = require('../../../js/constants/settings')
const tabActionConstants = require('../../common/constants/tabAction')
const ledgerStatuses = require('../../common/constants/ledgerStatuses')
const messages = require('../../../js/constants/messages')

// State
const ledgerState = require('../../common/state/ledgerState')
Expand Down Expand Up @@ -576,8 +577,17 @@ const ledgerReducer = (state, action, immutableAction) => {
state = ledgerApi.pageDataChanged(state, viewData, true)
break
}
case appConstants.APP_RUN_PROMOTION_CHECK:
{
state = ledgerApi.onRunPromotionCheck(state, getSetting(settings.PAYMENTS_ENABLED))
break
}
}
return state
}

process.on(messages.APP_INITIALIZED, () => {
ledgerApi.runPromotionCheck()
})

module.exports = ledgerReducer
6 changes: 6 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,12 @@ const appActions = {
tabId,
index
})
},

runPromotionCheck: function () {
dispatch({
actionType: appConstants.APP_RUN_PROMOTION_CHECK
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ const appConstants = {
APP_ON_TOR_INIT_PERCENTAGE: _,
APP_SET_TOR_NEW_IDENTITY: _,
APP_RESTART_TOR: _,
APP_RECREATE_TOR_TAB: _
APP_RECREATE_TOR_TAB: _,
APP_RUN_PROMOTION_CHECK: _
}

module.exports = mapValuesByKeys(appConstants)
16 changes: 16 additions & 0 deletions test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4161,4 +4161,20 @@ describe('ledger api unit tests', function () {
assert(onLedgerFuzzingSpy.withArgs(1000, true).calledOnce)
})
})

describe('runPromotionCheck', function () {
let onRunPromotionCheckSpy

before(function () {
onRunPromotionCheckSpy = sinon.spy(appActions, 'runPromotionCheck')
})

afterEach(function () {
onRunPromotionCheckSpy.reset()
})
it('calls runPromotionCheck', function () {
ledgerApi.runPromotionCheck()
assert(onRunPromotionCheckSpy.calledOnce)
})
})
})
23 changes: 22 additions & 1 deletion test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ describe('ledgerReducer unit tests', function () {
clearPaymentHistory: () => {},
deleteWallet: () => {},
addNewLocation: dummyModifyState,
synopsisNormalizer: dummyModifyState
synopsisNormalizer: dummyModifyState,
onRunPromotionCheck: () => {}
}
fakeLedgerState = {
resetPublishers: dummyModifyState,
Expand Down Expand Up @@ -1125,4 +1126,24 @@ describe('ledgerReducer unit tests', function () {
assert(deleteWalletSpy.calledOnce)
})
})

describe('APP_RUN_PROMOTION_CHECK', function () {
let onRunPromotionCheckSpy
before(function () {
onRunPromotionCheckSpy = sinon.spy(fakeLedgerApi, 'onRunPromotionCheck')
returnedState = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_RUN_PROMOTION_CHECK,
stateResult: 'state-result-goes-here'
}))
})
after(function () {
onRunPromotionCheckSpy.restore()
})
it('calls ledgerApi.onRunPromotionCheck', function () {
assert(onRunPromotionCheckSpy.calledOnce)
})
it('returns a modified state', function () {
assert.notDeepEqual(returnedState, appState)
})
})
})

0 comments on commit 0e87995

Please sign in to comment.