Skip to content
Permalink
Browse files

feat: store last session seen for faster loading

  • Loading branch information...
satello committed Jun 18, 2018
1 parent 9ef59a5 commit 430e49461394534cf20adc779a6b2e9841f9c7e3
@@ -57,9 +57,7 @@ class Arbitrator extends AbstractContract {
)

// FIXME do we want to store session?
// this._StoreProvider.updateUserProfile(account, {
// session: currentSession
// })
this._StoreProvider.updateUserSession(account, currentSession)
}

return this.getDisputesForUserFromStore(account)
@@ -207,6 +207,29 @@ class StoreProviderWrapper {
)
}

/**
* Update users last processed session.
* @param {string} userAddress - User's address.
* @param {string} session - The current session that the user has processed
* @returns {object} - HTTP response.
*/
updateUserSession = async (userAddress, session) => {
const getBodyFn = () =>
new Promise(resolve =>
resolve(
JSON.stringify({
session
})
)
)

return this.queueWriteRequest(
getBodyFn,
'POST',
`${this._storeUri}/${userAddress}/session`
)
}

/**
* Update the stored data on a contract for a user. Note that you cannot overwrite contract data.
* @param {string} userAddress - The user's address.
@@ -117,6 +117,7 @@ describe('Arbitrator', () => {
const mockSetUpUserProfile = jest.fn()
const mockGetDisputesForJuror = jest.fn()
const mockUpdateDisputeProfile = jest.fn()
const mockUpdateSession = jest.fn()
const mockDispute = {
arbitratorAddress: arbitratorAddress,
disputeId: '1',
@@ -131,7 +132,8 @@ describe('Arbitrator', () => {
session: 1
})
),
updateDisputeProfile: mockUpdateDisputeProfile
updateDisputeProfile: mockUpdateDisputeProfile,
updateUserSession: mockUpdateSession
}

arbitratorInstance.setStoreProviderInstance(mockStoreProvider)
@@ -170,6 +172,7 @@ describe('Arbitrator', () => {
appealDraws: mockDispute.appealDraws,
blockNumber: 1
})
expect(mockUpdateSession.mock.calls.length).toBe(1)
})
})
})

0 comments on commit 430e494

Please sign in to comment.
You can’t perform that action at this time.