Commit 356ae326 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'roadmap-performance-improvement' into 'master'

Roadmap - Refactor VueX action/mutation to improve performance

See merge request gitlab-org/gitlab!31841
parents ddcabec8 2b6443ba
...@@ -81,6 +81,7 @@ export const receiveEpicsSuccess = ( ...@@ -81,6 +81,7 @@ export const receiveEpicsSuccess = (
{ commit, dispatch, state, getters }, { commit, dispatch, state, getters },
{ rawEpics, newEpic, timeframeExtended }, { rawEpics, newEpic, timeframeExtended },
) => { ) => {
const epicIds = [];
const epics = rawEpics.reduce((filteredEpics, epic) => { const epics = rawEpics.reduce((filteredEpics, epic) => {
const formattedEpic = roadmapItemUtils.formatRoadmapItemDetails( const formattedEpic = roadmapItemUtils.formatRoadmapItemDetails(
epic, epic,
...@@ -100,11 +101,13 @@ export const receiveEpicsSuccess = ( ...@@ -100,11 +101,13 @@ export const receiveEpicsSuccess = (
newEpic, newEpic,
}); });
filteredEpics.push(formattedEpic); filteredEpics.push(formattedEpic);
commit(types.UPDATE_EPIC_IDS, formattedEpic.id); epicIds.push(formattedEpic.id);
} }
return filteredEpics; return filteredEpics;
}, []); }, []);
commit(types.UPDATE_EPIC_IDS, epicIds);
if (timeframeExtended) { if (timeframeExtended) {
const updatedEpics = state.epics.concat(epics); const updatedEpics = state.epics.concat(epics);
sortEpics(updatedEpics, state.sortedBy); sortEpics(updatedEpics, state.sortedBy);
......
...@@ -11,8 +11,8 @@ export default { ...@@ -11,8 +11,8 @@ export default {
state.epics = epics; state.epics = epics;
}, },
[types.UPDATE_EPIC_IDS](state, epicId) { [types.UPDATE_EPIC_IDS](state, epicIds) {
state.epicIds.push(epicId); state.epicIds.push(...epicIds);
}, },
[types.REQUEST_EPICS](state) { [types.REQUEST_EPICS](state) {
......
...@@ -94,7 +94,7 @@ describe('Roadmap Vuex Actions', () => { ...@@ -94,7 +94,7 @@ describe('Roadmap Vuex Actions', () => {
}, },
state, state,
[ [
{ type: types.UPDATE_EPIC_IDS, payload: mockRawEpic.id }, { type: types.UPDATE_EPIC_IDS, payload: [mockRawEpic.id] },
{ {
type: types.RECEIVE_EPICS_SUCCESS, type: types.RECEIVE_EPICS_SUCCESS,
payload: [ payload: [
...@@ -149,7 +149,7 @@ describe('Roadmap Vuex Actions', () => { ...@@ -149,7 +149,7 @@ describe('Roadmap Vuex Actions', () => {
}, },
state, state,
[ [
{ type: types.UPDATE_EPIC_IDS, payload: mockRawEpic.id }, { type: types.UPDATE_EPIC_IDS, payload: [mockRawEpic.id] },
{ {
type: types.RECEIVE_EPICS_FOR_TIMEFRAME_SUCCESS, type: types.RECEIVE_EPICS_FOR_TIMEFRAME_SUCCESS,
payload: [{ ...mockFormattedEpic, newEpic: true }], payload: [{ ...mockFormattedEpic, newEpic: true }],
......
...@@ -49,7 +49,7 @@ describe('Roadmap Store Mutations', () => { ...@@ -49,7 +49,7 @@ describe('Roadmap Store Mutations', () => {
describe('UPDATE_EPIC_IDS', () => { describe('UPDATE_EPIC_IDS', () => {
it('Should insert provided epicId to epicIds array in state', () => { it('Should insert provided epicId to epicIds array in state', () => {
mutations[types.UPDATE_EPIC_IDS](state, 22); mutations[types.UPDATE_EPIC_IDS](state, [22]);
expect(state.epicIds).toHaveLength(1); expect(state.epicIds).toHaveLength(1);
expect(state.epicIds[0]).toBe(22); expect(state.epicIds[0]).toBe(22);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment