mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-11-28 08:58:41 +02:00
Faster series selector
This commit is contained in:
parent
283f905d79
commit
43d04cd54e
@ -16,6 +16,13 @@ const blacklistedProperties = [
|
||||
'id'
|
||||
];
|
||||
|
||||
function createItemMap(data) {
|
||||
return data.reduce((acc, d, index) => {
|
||||
acc[d.id] = index;
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export default function createHandleActions(handlers, defaultState, section) {
|
||||
return handleActions({
|
||||
|
||||
@ -42,6 +49,7 @@ export default function createHandleActions(handlers, defaultState, section) {
|
||||
|
||||
if (_.isArray(payload.data)) {
|
||||
newState.items = payload.data;
|
||||
newState.itemMap = createItemMap(payload.data);
|
||||
} else {
|
||||
newState.item = payload.data;
|
||||
}
|
||||
@ -75,6 +83,7 @@ export default function createHandleActions(handlers, defaultState, section) {
|
||||
newState.items.splice(index, 1, { ...item, ...otherProps });
|
||||
} else if (!updateOnly) {
|
||||
newState.items.push({ ...otherProps });
|
||||
newState.itemMap = createItemMap(newState.items);
|
||||
}
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
@ -111,6 +120,8 @@ export default function createHandleActions(handlers, defaultState, section) {
|
||||
newState.items = [...newState.items];
|
||||
_.remove(newState.items, { id: payload.id });
|
||||
|
||||
newState.itemMap = createItemMap(newState.items);
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import createAllSeriesSelector from './createAllSeriesSelector';
|
||||
|
||||
function createSeriesSelector() {
|
||||
return createSelector(
|
||||
(state, { seriesId }) => seriesId,
|
||||
createAllSeriesSelector(),
|
||||
(seriesId, allSeries) => {
|
||||
return allSeries.find((series) => series.id === seriesId);
|
||||
(state) => state.series.itemMap,
|
||||
(state) => state.series.items,
|
||||
(seriesId, itemMap, allSeries) => {
|
||||
return allSeries[itemMap[seriesId]];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user