Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
feat: store last session seen for faster loading
Browse files Browse the repository at this point in the history
  • Loading branch information
satello committed Jun 18, 2018
1 parent 9ef59a5 commit 430e494
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/contracts/abstractions/Arbitrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions src/utils/StoreProviderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/contracts/abstractions/Arbitrator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -131,7 +132,8 @@ describe('Arbitrator', () => {
session: 1
})
),
updateDisputeProfile: mockUpdateDisputeProfile
updateDisputeProfile: mockUpdateDisputeProfile,
updateUserSession: mockUpdateSession
}

arbitratorInstance.setStoreProviderInstance(mockStoreProvider)
Expand Down Expand Up @@ -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.