This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cache registry reverses in local storage #4182
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
702e7a2
cache reverses in localStorage
derhuerst 9176416
merge master into jr-reverse-localstorage
derhuerst 62f158a
bugfixes :bug:, linting fixes :shirt:
derhuerst 1c2adc3
registry caching: store last block
derhuerst 293372d
merge master into jr-reverse-localstorage
derhuerst 9eb9714
registry caching: store per chain
derhuerst 42740d6
merge master into jr-reverse-localstorage
derhuerst 1ff7552
localStorage -> store
derhuerst b0bc0b4
code style :sparkles:
derhuerst d9073da
code style :shirt:
derhuerst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
registry caching: store last block
- Loading branch information
commit 1c2adc31d72fe89ffc65c049ec795d3a9697dc64
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,21 +23,28 @@ import registryABI from '~/contracts/abi/registry.json'; | |
import { setReverse, startCachingReverses } from './actions'; | ||
|
||
const read = () => { | ||
const data = window.localStorage.getItem('registry-reverses'); | ||
if (!data) { | ||
const reverses = window.localStorage.getItem('registry-reverses'); | ||
const lastBlock = window.localStorage.getItem('registry-reverses-last-block'); | ||
if (!reverses || !lastBlock) { | ||
return null; | ||
} | ||
|
||
try { | ||
return JSON.parse(data); | ||
return { | ||
reverses: JSON.parse(reverses), | ||
lastBlock: JSON.parse(lastBlock) | ||
}; | ||
} catch (_) { | ||
return null; | ||
} | ||
}; | ||
|
||
const write = debounce((getReverses) => { | ||
const write = debounce((getReverses, getLastBlock) => { | ||
const reverses = getReverses(); | ||
const lastBlock = getLastBlock(); | ||
|
||
window.localStorage.setItem('registry-reverses', JSON.stringify(reverses)); | ||
window.localStorage.setItem('registry-reverses-last-block', JSON.stringify(lastBlock)); | ||
}, 20000); | ||
|
||
export default (api) => (store) => { | ||
|
@@ -84,12 +91,23 @@ export default (api) => (store) => { | |
case 'startCachingReverses': | ||
const { registry } = Contracts.get(); | ||
|
||
const cached = read(); | ||
if (cached) { | ||
Object | ||
.entries(cached.reverses) | ||
.forEach(([ address, reverse ]) => store.dispatch(setReverse(address, reverse))); | ||
} | ||
|
||
registry.getInstance() | ||
.then((instance) => api.newContract(registryABI, instance.address)) | ||
.then((_contract) => { | ||
contract = _contract; | ||
|
||
subscription = subscribeToEvents(_contract, ['ReverseConfirmed', 'ReverseRemoved']); | ||
subscription = subscribeToEvents(_contract, [ | ||
'ReverseConfirmed', 'ReverseRemoved' | ||
], { | ||
from: cached ? cached.lastBlock : 0 | ||
}); | ||
subscription.on('log', onLog); | ||
|
||
timeout = setTimeout(checkReverses, 10000); | ||
|
@@ -100,13 +118,6 @@ export default (api) => (store) => { | |
throw err; | ||
}); | ||
|
||
const cached = read(); | ||
if (cached) { | ||
Object | ||
.entries(cached) | ||
.forEach(([ address, reverse ]) => store.dispatch(setReverse(address, reverse))); | ||
} | ||
|
||
break; | ||
case 'stopCachingReverses': | ||
if (subscription) { | ||
|
@@ -123,7 +134,10 @@ export default (api) => (store) => { | |
|
||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for blank line before. |
||
case 'setReverse': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line before. |
||
write(() => store.getState().registry.reverse); | ||
write( | ||
() => store.getState().registry.reverse, | ||
() => +store.getState().nodeStatus.blockNumber | ||
); | ||
next(action); | ||
|
||
break; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ export default (state = initialState, action) => { | |
return state; | ||
} | ||
|
||
return { ...state, reverse: { | ||
return { reverse: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would prefer spacey blocks reverse on next line just aligning with what we have. (Plus each entry on it's own line) |
||
...state.reverse, [ action.address ]: action.reverse | ||
} }; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
OCD-related comment (plus I'm old) - some spacing between vars and action (i.e. blank line here) would be appreciated.