Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve collection edit performance #3185

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions ui/redux/actions/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,12 @@ export const doCollectionEdit =
const isPrivateVersion = selectHasPrivateCollectionForId(state, collectionId);
const { uris, remove, replace, order, type, isPreview } = params;

await dispatch(doFetchItemsInCollection({ collectionId }));
state = getState();
const hasItemsResolved = selectCollectionHasItemsResolvedForId(state, collectionId);
let hasItemsResolved = selectCollectionHasItemsResolvedForId(state, collectionId);
if (!hasItemsResolved && !isPrivateVersion) {
await dispatch(doFetchItemsInCollection({ collectionId }));
state = getState();
hasItemsResolved = selectCollectionHasItemsResolvedForId(state, collectionId);
}
if (!hasItemsResolved && !isPrivateVersion) {
return dispatch(doToast({ message: __('Failed to resolve collection items. Please try again.'), isError: true }));
}
Expand Down Expand Up @@ -605,8 +608,6 @@ export const doCollectionEdit =
currentUrls.splice(order.to, 0, movedItem);
}

await dispatch(doRemoveFromUpdatedCollectionsForCollectionId(collectionId));

const isQueue = collectionId === COLS.QUEUE_ID;
const title = params.title || params.name;

Expand All @@ -632,10 +633,6 @@ export const doCollectionEdit =
},
},
});
// Needs to be run after collection_edit is dispatched, or saving changes doesn't work from edit page
if (!isPreview) {
dispatch(doRemoveFromUnsavedChangesCollectionsForCollectionId(collectionId));
}
success();
});
};
Expand Down
12 changes: 11 additions & 1 deletion ui/redux/reducers/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,21 @@ const collectionsReducer = handleActions(
const newCollection = Object.assign({}, collection);
newCollection.updatedAt = getCurrentTimeInSec();

return {
const newState = {
...state,
[collectionKey]: { ...currentCollections, [id]: newCollection },
lastUsedCollection: id,
};

// Remove un-wanted versions of the list
[COLS.KEYS.UPDATED, COLS.KEYS.UNSAVED_CHANGES].forEach((key) => {
if (collectionKey !== key) {
const { [id]: _, ...remainingCollections } = state[key];
newState[key] = remainingCollections;
}
});

return newState;
},

[ACTIONS.USER_STATE_POPULATE]: (state, action) => {
Expand Down
Loading