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:
parent
2241a15ee9
commit
cf4fe6cab8
3 changed files with 16 additions and 12 deletions
|
@ -140,7 +140,7 @@ const appendNormalizedTimeline = (state, timeline, statuses, next) => {
|
|||
return state.updateIn([timeline, 'items'], Immutable.List(), list => list.concat(moreIds));
|
||||
};
|
||||
|
||||
const normalizeAccountTimeline = (state, accountId, statuses, replace = false) => {
|
||||
const normalizeAccountTimeline = (state, accountId, statuses, replace, next) => {
|
||||
let ids = Immutable.List();
|
||||
|
||||
statuses.forEach((status, i) => {
|
||||
|
@ -151,11 +151,11 @@ const normalizeAccountTimeline = (state, accountId, statuses, replace = false) =
|
|||
return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
|
||||
.set('isLoading', false)
|
||||
.set('loaded', true)
|
||||
.set('next', true)
|
||||
.set('next', next)
|
||||
.update('items', Immutable.List(), list => (replace ? ids : ids.concat(list))));
|
||||
};
|
||||
|
||||
const normalizeAccountMediaTimeline = (state, accountId, statuses) => {
|
||||
const normalizeAccountMediaTimeline = (state, accountId, statuses, replace, next) => {
|
||||
let ids = Immutable.List();
|
||||
|
||||
statuses.forEach((status, i) => {
|
||||
|
@ -165,8 +165,8 @@ const normalizeAccountMediaTimeline = (state, accountId, statuses) => {
|
|||
|
||||
return state.updateIn(['accounts_media_timelines', accountId], Immutable.Map(), map => map
|
||||
.set('isLoading', false)
|
||||
.set('next', true)
|
||||
.update('items', Immutable.List(), list => ids.concat(list)));
|
||||
.set('next', next)
|
||||
.update('items', Immutable.List(), list => (replace ? ids : ids.concat(list))));
|
||||
};
|
||||
|
||||
const appendNormalizedAccountTimeline = (state, accountId, statuses, next) => {
|
||||
|
@ -335,7 +335,7 @@ export default function timelines(state = initialState, action) {
|
|||
case ACCOUNT_TIMELINE_EXPAND_FAIL:
|
||||
return state.updateIn(['accounts_timelines', action.id], Immutable.Map(), map => map.set('isLoading', false));
|
||||
case ACCOUNT_TIMELINE_FETCH_SUCCESS:
|
||||
return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace);
|
||||
return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace, action.next);
|
||||
case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
|
||||
return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.next);
|
||||
case ACCOUNT_MEDIA_TIMELINE_FETCH_REQUEST:
|
||||
|
@ -345,7 +345,7 @@ export default function timelines(state = initialState, action) {
|
|||
case ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL:
|
||||
return state.updateIn(['accounts_media_timelines', action.id], Immutable.Map(), map => map.set('isLoading', false));
|
||||
case ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS:
|
||||
return normalizeAccountMediaTimeline(state, action.id, Immutable.fromJS(action.statuses));
|
||||
return normalizeAccountMediaTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace, action.next);
|
||||
case ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS:
|
||||
return appendNormalizedAccountMediaTimeline(state, action.id, Immutable.fromJS(action.statuses), action.next);
|
||||
case ACCOUNT_BLOCK_SUCCESS:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue