From 430e49461394534cf20adc779a6b2e9841f9c7e3 Mon Sep 17 00:00:00 2001 From: Sam Vitello Date: Mon, 18 Jun 2018 14:34:25 -0600 Subject: [PATCH] feat: store last session seen for faster loading --- src/contracts/abstractions/Arbitrator.js | 4 +--- src/utils/StoreProviderWrapper.js | 23 +++++++++++++++++++ .../contracts/abstractions/Arbitrator.test.js | 5 +++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/contracts/abstractions/Arbitrator.js b/src/contracts/abstractions/Arbitrator.js index 3dce776..4991634 100644 --- a/src/contracts/abstractions/Arbitrator.js +++ b/src/contracts/abstractions/Arbitrator.js @@ -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) diff --git a/src/utils/StoreProviderWrapper.js b/src/utils/StoreProviderWrapper.js index 6a24f84..461c897 100644 --- a/src/utils/StoreProviderWrapper.js +++ b/src/utils/StoreProviderWrapper.js @@ -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. diff --git a/tests/unit/contracts/abstractions/Arbitrator.test.js b/tests/unit/contracts/abstractions/Arbitrator.test.js index 80ed59d..0d7e6af 100644 --- a/tests/unit/contracts/abstractions/Arbitrator.test.js +++ b/tests/unit/contracts/abstractions/Arbitrator.test.js @@ -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) }) }) })