a3398843c2
Frequently used; top in perf profile Most of the time, you already have the claim object in the current context. `selectClaimIsMineForUri` will retrieve the claim again, which is wasteful, even if it is memoized (looking up the cache still takes time). Break apart the logic and added the alternative `selectClaimIsMine` for faster lookup. Co-authored-by: infinite-persistence <inf.persistence@gmail.com>
20 lines
817 B
JavaScript
20 lines
817 B
JavaScript
// @flow
|
|
import { createSelector } from 'reselect';
|
|
import { selectClaimIdForUri } from 'redux/selectors/claims';
|
|
|
|
type State = { claims: any };
|
|
const selectState = state => state.stats || {};
|
|
export const selectViewCount = createSelector(selectState, state => state.viewCountById);
|
|
export const selectSubCount = createSelector(selectState, state => state.subCountById);
|
|
|
|
export const selectViewCountForUri = (state: State, uri: string) => {
|
|
const claimId = selectClaimIdForUri(state, uri);
|
|
const viewCountById = selectViewCount(state);
|
|
return claimId ? viewCountById[claimId] || 0 : 0;
|
|
};
|
|
|
|
export const selectSubCountForUri = (state: State, uri: string) => {
|
|
const claimId = selectClaimIdForUri(state, uri);
|
|
const subCountById = selectSubCount(state);
|
|
return claimId ? subCountById[claimId] || 0 : 0;
|
|
};
|