More use of next link header on account (media) timelines (#3311)

This will reduce requests on who have only few statuses.

- Use next link header to detect more items from first request
- Omit next link header if result items are fewer than requested count
(It had omit it only if result was empty before)
This commit is contained in:
unarist 2017-05-26 00:09:13 +09:00 committed by Eugen Rochko
parent 2241a15ee9
commit cf4fe6cab8
3 changed files with 16 additions and 12 deletions

View file

@ -115,7 +115,8 @@ export function fetchAccountTimeline(id, replace = false) {
dispatch(fetchAccountTimelineRequest(id, skipLoading));
api(getState).get(`/api/v1/accounts/${id}/statuses`, { params }).then(response => {
dispatch(fetchAccountTimelineSuccess(id, response.data, replace, skipLoading));
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(fetchAccountTimelineSuccess(id, response.data, replace, skipLoading, next));
}).catch(error => {
dispatch(fetchAccountTimelineFail(id, error, skipLoading));
});
@ -138,7 +139,8 @@ export function fetchAccountMediaTimeline(id, replace = false) {
dispatch(fetchAccountMediaTimelineRequest(id, skipLoading));
api(getState).get(`/api/v1/accounts/${id}/statuses`, { params }).then(response => {
dispatch(fetchAccountMediaTimelineSuccess(id, response.data, replace, skipLoading));
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(fetchAccountMediaTimelineSuccess(id, response.data, replace, skipLoading, next));
}).catch(error => {
dispatch(fetchAccountMediaTimelineFail(id, error, skipLoading));
});
@ -283,13 +285,14 @@ export function fetchAccountTimelineRequest(id, skipLoading) {
};
};
export function fetchAccountTimelineSuccess(id, statuses, replace, skipLoading) {
export function fetchAccountTimelineSuccess(id, statuses, replace, skipLoading, next) {
return {
type: ACCOUNT_TIMELINE_FETCH_SUCCESS,
id,
statuses,
replace,
skipLoading,
next,
};
};
@ -311,13 +314,14 @@ export function fetchAccountMediaTimelineRequest(id, skipLoading) {
};
};
export function fetchAccountMediaTimelineSuccess(id, statuses, replace, skipLoading) {
export function fetchAccountMediaTimelineSuccess(id, statuses, replace, skipLoading, next) {
return {
type: ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS,
id,
statuses,
replace,
skipLoading,
next,
};
};