From ed753a7f9eb98884d880cc9fac23def01f54e62c Mon Sep 17 00:00:00 2001 From: Arnei Date: Fri, 19 Jan 2024 15:10:53 +0100 Subject: [PATCH] Add memoization to "selectVideos" selector On behalf of a web console warning in the track selection view, this adds memoization to the "selectVideos" selector. This seems reasonable if just for the fact that track availability should never ever change. --- src/redux/videoSlice.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/redux/videoSlice.ts b/src/redux/videoSlice.ts index 12f0bbfdd..50153c4de 100644 --- a/src/redux/videoSlice.ts +++ b/src/redux/videoSlice.ts @@ -1,4 +1,4 @@ -import { createSlice, nanoid, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit"; +import { createSlice, nanoid, createAsyncThunk, PayloadAction, createSelector } from "@reduxjs/toolkit"; import { client } from "../util/client"; import { Segment, httpRequestState, Track, Workflow, SubtitlesFromOpencast } from "../types"; @@ -432,8 +432,10 @@ export const selectOriginalThumbnails = state.videoState.originalThumbnails; // Selectors mainly pertaining to the information fetched from Opencast -export const selectVideos = (state: { videoState: { tracks: video["tracks"]; }; }) => - state.videoState.tracks.filter((track: Track) => track.video_stream.available === true); +export const selectVideos = createSelector( + [(state: { videoState: { tracks: video["tracks"]; }; }) => state.videoState.tracks], + tracks => tracks.filter((track: Track) => track.video_stream.available === true) +); export const selectVideoURL = (state: { videoState: { videoURLs: video["videoURLs"]; }; }) => state.videoState.videoURLs; export const selectVideoCount = (state: { videoState: { videoCount: video["videoCount"]; }; }) =>