mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
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)
This commit is contained in:
parent
5b07046396
commit
959b8ed83e
@ -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 movieListEqual(a, b) {
|
||||||
|
return hasDifferentItemsOrOrder(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
const createMovieEqualSelector = createSelectorCreator(
|
||||||
|
defaultMemoize,
|
||||||
|
movieListEqual
|
||||||
|
);
|
||||||
|
|
||||||
function createMovieClientSideCollectionItemsSelector(uiSection) {
|
function createMovieClientSideCollectionItemsSelector(uiSection) {
|
||||||
return createDeepEqualSelector(
|
return createMovieEqualSelector(
|
||||||
createUnoptimizedSelector(uiSection),
|
createUnoptimizedSelector(uiSection),
|
||||||
(movies) => movies
|
(movies) => movies
|
||||||
);
|
);
|
||||||
|
@ -88,7 +88,7 @@ private string GetMovieCoverPath(int movieId)
|
|||||||
return Path.Combine(_coverRootFolder, movieId.ToString());
|
return Path.Combine(_coverRootFolder, movieId.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureCovers(Movie movie)
|
private bool EnsureCovers(Movie movie)
|
||||||
{
|
{
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
var toResize = new List<Tuple<MediaCover, bool>>();
|
var toResize = new List<Tuple<MediaCover, bool>>();
|
||||||
|
@ -54,7 +54,6 @@ public MovieResource()
|
|||||||
public string FolderName { get; set; }
|
public string FolderName { get; set; }
|
||||||
|
|
||||||
public int Runtime { get; set; }
|
public int Runtime { get; set; }
|
||||||
public DateTime? LastInfoSync { get; set; }
|
|
||||||
public string CleanTitle { get; set; }
|
public string CleanTitle { get; set; }
|
||||||
public string ImdbId { get; set; }
|
public string ImdbId { get; set; }
|
||||||
public int TmdbId { get; set; }
|
public int TmdbId { get; set; }
|
||||||
@ -114,7 +113,6 @@ public static MovieResource ToResource(this Movie model)
|
|||||||
FolderName = model.FolderName(),
|
FolderName = model.FolderName(),
|
||||||
|
|
||||||
Runtime = model.Runtime,
|
Runtime = model.Runtime,
|
||||||
LastInfoSync = model.LastInfoSync,
|
|
||||||
CleanTitle = model.CleanTitle,
|
CleanTitle = model.CleanTitle,
|
||||||
ImdbId = model.ImdbId,
|
ImdbId = model.ImdbId,
|
||||||
TitleSlug = model.TitleSlug,
|
TitleSlug = model.TitleSlug,
|
||||||
@ -175,7 +173,6 @@ public static MovieResource ToResource(this Movie model, IUpgradableSpecificatio
|
|||||||
FolderName = model.FolderName(),
|
FolderName = model.FolderName(),
|
||||||
|
|
||||||
Runtime = model.Runtime,
|
Runtime = model.Runtime,
|
||||||
LastInfoSync = model.LastInfoSync,
|
|
||||||
CleanTitle = model.CleanTitle,
|
CleanTitle = model.CleanTitle,
|
||||||
ImdbId = model.ImdbId,
|
ImdbId = model.ImdbId,
|
||||||
TitleSlug = model.TitleSlug,
|
TitleSlug = model.TitleSlug,
|
||||||
@ -228,7 +225,6 @@ public static Movie ToModel(this MovieResource resource)
|
|||||||
MinimumAvailability = resource.MinimumAvailability,
|
MinimumAvailability = resource.MinimumAvailability,
|
||||||
|
|
||||||
Runtime = resource.Runtime,
|
Runtime = resource.Runtime,
|
||||||
LastInfoSync = resource.LastInfoSync,
|
|
||||||
CleanTitle = resource.CleanTitle,
|
CleanTitle = resource.CleanTitle,
|
||||||
ImdbId = resource.ImdbId,
|
ImdbId = resource.ImdbId,
|
||||||
TitleSlug = resource.TitleSlug,
|
TitleSlug = resource.TitleSlug,
|
||||||
|
Loading…
Reference in New Issue
Block a user