Speed up/optimize loading of statuses, context and cards by not re-fetching what is already loaded

lolsob-rspec
Eugen Rochko 2017-02-17 01:34:37 +01:00
parent 7f9d6d0160
commit 52a0427d24
2 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,10 @@ export const STATUS_CARD_FETCH_FAIL = 'STATUS_CARD_FETCH_FAIL';
export function fetchStatusCard(id) { export function fetchStatusCard(id) {
return (dispatch, getState) => { return (dispatch, getState) => {
if (getState().getIn(['cards', id], null) !== null) {
return;
}
dispatch(fetchStatusCardRequest(id)); dispatch(fetchStatusCardRequest(id));
api(getState).get(`/api/v1/statuses/${id}/card`).then(response => { api(getState).get(`/api/v1/statuses/${id}/card`).then(response => {

View File

@ -27,12 +27,17 @@ export function fetchStatus(id) {
return (dispatch, getState) => { return (dispatch, getState) => {
const skipLoading = getState().getIn(['statuses', id], null) !== null; const skipLoading = getState().getIn(['statuses', id], null) !== null;
dispatch(fetchContext(id));
dispatch(fetchStatusCard(id));
if (skipLoading) {
return;
}
dispatch(fetchStatusRequest(id, skipLoading)); dispatch(fetchStatusRequest(id, skipLoading));
api(getState).get(`/api/v1/statuses/${id}`).then(response => { api(getState).get(`/api/v1/statuses/${id}`).then(response => {
dispatch(fetchStatusSuccess(response.data, skipLoading)); dispatch(fetchStatusSuccess(response.data, skipLoading));
dispatch(fetchContext(id));
dispatch(fetchStatusCard(id));
}).catch(error => { }).catch(error => {
dispatch(fetchStatusFail(id, error, skipLoading)); dispatch(fetchStatusFail(id, error, skipLoading));
}); });