Fixed: Speed up UI during refresh

Don't update state if we know items are equal to avoid reselections.
Don't pass LastInfoUpdate to frontend to prevent useless updates (the
field isn't used)
pull/1689/head
ta264 5 years ago committed by Qstick
parent e1a62af586
commit 014eb27a26

@ -65,18 +65,31 @@ export default function createHandleActions(handlers, defaultState, section) {
if (section === baseSection) { if (section === baseSection) {
const newState = getSectionState(state, payloadSection); const newState = getSectionState(state, payloadSection);
const items = newState.items; const items = newState.items;
const index = _.findIndex(items, { id: payload.id });
if (!newState.itemMap) {
newState.itemMap = _.zipObject(_.map(items, 'id'), _.range(items.length));
}
const index = payload.id in newState.itemMap ? newState.itemMap[payload.id] : -1;
newState.items = [...items]; newState.items = [...items];
// TODO: Move adding to it's own reducer // TODO: Move adding to it's own reducer
if (index >= 0) { if (index >= 0) {
const item = items[index]; const item = items[index];
const newItem = { ...item, ...otherProps };
newState.items.splice(index, 1, { ...item, ...otherProps }); // if the item to update is equal to existing, then don't actually update
// to prevent costly reselections
if (_.isEqual(item, newItem)) {
return state;
}
newState.items.splice(index, 1, newItem);
} else if (!updateOnly) { } else if (!updateOnly) {
newState.items.push({ ...otherProps }); const newIndex = newState.items.push({ ...otherProps }) - 1;
newState.itemMap = _.zipObject(_.map(newState.items, 'id'), _.range(newState.items.length));
newState.itemMap[payload.id] = newIndex;
} }
return updateSectionState(state, payloadSection, newState); return updateSectionState(state, payloadSection, newState);

@ -1,6 +1,6 @@
import { createSelector } from 'reselect'; import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect';
import createDeepEqualSelector from './createDeepEqualSelector';
import createClientSideCollectionSelector from './createClientSideCollectionSelector'; import createClientSideCollectionSelector from './createClientSideCollectionSelector';
import hasDifferentItemsOrOrder from 'Utilities/Object/hasDifferentItemsOrOrder';
function createUnoptimizedSelector(uiSection) { function createUnoptimizedSelector(uiSection) {
return createSelector( return createSelector(
@ -26,8 +26,17 @@ function createUnoptimizedSelector(uiSection) {
); );
} }
function artistListEqual(a, b) {
return hasDifferentItemsOrOrder(a, b);
}
const createArtistEqualSelector = createSelectorCreator(
defaultMemoize,
artistListEqual
);
function createArtistClientSideCollectionItemsSelector(uiSection) { function createArtistClientSideCollectionItemsSelector(uiSection) {
return createDeepEqualSelector( return createArtistEqualSelector(
createUnoptimizedSelector(uiSection), createUnoptimizedSelector(uiSection),
(artist) => artist (artist) => artist
); );

@ -20,8 +20,6 @@ namespace Lidarr.Api.V1.Artist
public bool Ended => Status == ArtistStatusType.Ended; public bool Ended => Status == ArtistStatusType.Ended;
public DateTime? LastInfoSync { get; set; }
public string ArtistName { get; set; } public string ArtistName { get; set; }
public string ForeignArtistId { get; set; } public string ForeignArtistId { get; set; }
public string MBId { get; set; } public string MBId { get; set; }
@ -96,8 +94,6 @@ namespace Lidarr.Api.V1.Artist
AlbumFolder = model.AlbumFolder, AlbumFolder = model.AlbumFolder,
Monitored = model.Monitored, Monitored = model.Monitored,
LastInfoSync = model.LastInfoSync,
CleanName = model.CleanName, CleanName = model.CleanName,
ForeignArtistId = model.Metadata.Value.ForeignArtistId, ForeignArtistId = model.Metadata.Value.ForeignArtistId,
@ -146,7 +142,6 @@ namespace Lidarr.Api.V1.Artist
AlbumFolder = resource.AlbumFolder, AlbumFolder = resource.AlbumFolder,
Monitored = resource.Monitored, Monitored = resource.Monitored,
LastInfoSync = resource.LastInfoSync,
CleanName = resource.CleanName, CleanName = resource.CleanName,
RootFolderPath = resource.RootFolderPath, RootFolderPath = resource.RootFolderPath,

Loading…
Cancel
Save