Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

cache registry reverses in local storage #4182

Merged
merged 10 commits into from Jan 20, 2017
Merged

Conversation

derhuerst
Copy link
Contributor

@derhuerst derhuerst commented Jan 16, 2017

Part of #4096.

still to do:

  • store the cache per chain

@derhuerst derhuerst added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M7-ui labels Jan 16, 2017
@derhuerst derhuerst added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Jan 18, 2017
import Contracts from '~/contracts';
import subscribeToEvents from '~/util/subscribe-to-events';

import registryABI from '~/contracts/abi/registry.json';

import { setReverse, startCachingReverses } from './actions';

const read = (chain) => {
const reverses = window.localStorage.getItem(`${chain}-registry-reverses`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Would prefer using store (i.e. import store from 'store';)
  2. Would prefer the @ngotchac introduced _parity:: prefix (still need to migrate old)
  3. Would prefer :: seperators as per above convention
  4. Would prefer <prefix>::<type>::<subtype>, i.e. _partity::reverse::${chain}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 👍
    2.-3. Is there a specific reason for this? the . notation seems to be a de-facto standard. I agree with prefixing with parity, but why _parity? Does that help somehow, except worse readability?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not meant to be read by humans. :)

I just want everything to align with our codebase de-facto standards we have in-place now. I don't think what we have is 100% perfect, but it also doesn't detract and is consistent at least in all the new code. A good step.

We already have a mix now of old that still needs to be migrated, I would not like to add another way of doing things and make things even worse.

logLevel as an exception is tolerated since we can actually direct people to change manually in case of bugs and in this case since there is manual interaction it makes the simpler format better.

const read = (chain) => {
const reverses = window.localStorage.getItem(`${chain}-registry-reverses`);
const lastBlock = window.localStorage.getItem(`${chain}-registry-reverses-last-block`);
if (!reverses || !lastBlock) {
Copy link
Contributor

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.

const reverses = getReverses();
const lastBlock = getLastBlock();

window.localStorage.setItem(`${chain}-registry-reverses`, JSON.stringify(reverses));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional bonus for using store (as commented above) - no need to manually strigify

break;
case 'setReverse':
write(
() => store.getState().nodeStatus.netChain,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just pass the values in as opposed to passing in a function that retrieves the values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Premature optimization. 😉 write gets called quite often. For all past & new reverse events.

@@ -24,7 +24,7 @@ export default (state = initialState, action) => {
return state;
}

return { ...state, reverse: {
return { reverse: {
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

@jacogr jacogr added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 19, 2017
@derhuerst derhuerst added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jan 19, 2017
const STORE_KEY = '_parity::reverses';

const read = (chain) => {
const reverses = store.get(`${STORE_KEY}::${chain}::data`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably make sense to const-ify data & lastBlock since it is used in multiple places. (Not a crisis either way)


const read = (chain) => {
const reverses = store.get(`${STORE_KEY}::${chain}::data`);
const lastBlock = store.get(`${STORE_KEY}::${chain}::last-block`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer lastBlock to last-block. Rationale -

  1. First in with the keys we already have in storage
  2. Fits in with the fact that we do camelCase for identifiers & filenames globally

if (!reverses || !lastBlock) {
return null;
}
return { reverses, lastBlock };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line before return.

@@ -91,6 +127,17 @@ export default (api) => (store) => {
clearTimeout(timeout);
}

write.flush();

break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for blank line before.

write.flush();

break;
case 'setReverse':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line before.

@jacogr
Copy link
Contributor

jacogr commented Jan 19, 2017

Couple of small style & naming niggles, otherwise looks ok.

@jacogr jacogr added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 20, 2017
@jacogr jacogr merged commit df9110d into master Jan 20, 2017
@derhuerst derhuerst deleted the jr-reverse-localstorage branch January 26, 2017 17:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants