Livestream category improvements #7115

Merged
infinite-persistence merged 15 commits from ip/category.livestream into master 2021-09-24 16:26:22 +02:00
3 changed files with 22 additions and 10 deletions
Showing only changes of commit 39c7159f2e - Show all commits

View file

@ -26,7 +26,8 @@ declare type LivestreamState = {
viewersById: {}, viewersById: {},
fetchingActiveLivestreams: boolean, fetchingActiveLivestreams: boolean,
activeLivestreams: ?LivestreamInfo, activeLivestreams: ?LivestreamInfo,
lastFetchedActiveLivestreams: number, activeLivestreamsLastFetchedDate: number,
activeLivestreamsLastFetchedOptions: {},
} }
declare type LivestreamInfo = { declare type LivestreamInfo = {

View file

@ -35,13 +35,21 @@ export const doFetchNoSourceClaims = (channelId: string) => async (dispatch: Dis
const FETCH_ACTIVE_LIVESTREAMS_MIN_INTERVAL_MS = 5 * 60 * 1000; const FETCH_ACTIVE_LIVESTREAMS_MIN_INTERVAL_MS = 5 * 60 * 1000;
export const doFetchActiveLivestreams = (forceFetch: boolean) => { export const doFetchActiveLivestreams = (
orderBy: Array<string> = ['release_time'],
pageSize: number = 50,
forceFetch: boolean = false
) => {
return async (dispatch: Dispatch, getState: GetState) => { return async (dispatch: Dispatch, getState: GetState) => {
const state = getState(); const state = getState();
const now = Date.now(); const now = Date.now();
const timeDelta = now - state.livestream.lastFetchedActiveLivestreams; const timeDelta = now - state.livestream.activeLivestreamsLastFetchedDate;
if (!forceFetch && timeDelta < FETCH_ACTIVE_LIVESTREAMS_MIN_INTERVAL_MS) { const prevOptions = state.livestream.activeLivestreamsLastFetchedOptions;
const nextOptions = { page_size: pageSize, order_by: orderBy };
const sameOptions = JSON.stringify(prevOptions) === JSON.stringify(nextOptions);
if (!forceFetch && sameOptions && timeDelta < FETCH_ACTIVE_LIVESTREAMS_MIN_INTERVAL_MS) {
dispatch({ type: ACTIONS.FETCH_ACTIVE_LIVESTREAMS_SKIPPED }); dispatch({ type: ACTIONS.FETCH_ACTIVE_LIVESTREAMS_SKIPPED });
return; return;
} }
@ -71,11 +79,11 @@ export const doFetchActiveLivestreams = (forceFetch: boolean) => {
// live. The UI usually just wants to report the latest claim, so we // live. The UI usually just wants to report the latest claim, so we
// query that store it in `latestClaimUri`. // query that store it in `latestClaimUri`.
doClaimSearch({ doClaimSearch({
page_size: 50, page_size: nextOptions.page_size,
has_no_source: true, has_no_source: true,
channel_ids: Object.keys(activeLivestreams), channel_ids: Object.keys(activeLivestreams),
claim_type: ['stream'], claim_type: ['stream'],
order_by: ['release_time'], // ** order_by: nextOptions.order_by, // **
limit_claims_per_channel: 1, // ** limit_claims_per_channel: 1, // **
no_totals: true, no_totals: true,
}) })
@ -97,7 +105,8 @@ export const doFetchActiveLivestreams = (forceFetch: boolean) => {
type: ACTIONS.FETCH_ACTIVE_LIVESTREAMS_COMPLETED, type: ACTIONS.FETCH_ACTIVE_LIVESTREAMS_COMPLETED,
data: { data: {
activeLivestreams, activeLivestreams,
lastFetchedActiveLivestreams: now, activeLivestreamsLastFetchedDate: now,
activeLivestreamsLastFetchedOptions: nextOptions,
}, },
}); });
}) })

View file

@ -7,7 +7,8 @@ const defaultState: LivestreamState = {
viewersById: {}, viewersById: {},
fetchingActiveLivestreams: false, fetchingActiveLivestreams: false,
activeLivestreams: null, activeLivestreams: null,
lastFetchedActiveLivestreams: 0, activeLivestreamsLastFetchedDate: 0,
activeLivestreamsLastFetchedOptions: {},
}; };
export default handleActions( export default handleActions(
@ -46,12 +47,13 @@ export default handleActions(
return { ...state, fetchingActiveLivestreams: false }; return { ...state, fetchingActiveLivestreams: false };
}, },
[ACTIONS.FETCH_ACTIVE_LIVESTREAMS_COMPLETED]: (state: LivestreamState, action: any) => { [ACTIONS.FETCH_ACTIVE_LIVESTREAMS_COMPLETED]: (state: LivestreamState, action: any) => {
const { activeLivestreams, lastFetchedActiveLivestreams } = action.data; const { activeLivestreams, activeLivestreamsLastFetchedDate, activeLivestreamsLastFetchedOptions } = action.data;
return { return {
...state, ...state,
fetchingActiveLivestreams: false, fetchingActiveLivestreams: false,
activeLivestreams, activeLivestreams,
lastFetchedActiveLivestreams, activeLivestreamsLastFetchedDate,
activeLivestreamsLastFetchedOptions,
}; };
}, },
}, },