Open
Description
Steps to reproduce
When calling find action with a resulting dataset of more than 500 records, it takes 15 seconds to update the store.
Expected behavior
Faster store update
Actual behavior
takes 15 sec.
System configuration
Tell us about the applicable parts of your setup.
Module versions (especially the part that's not working): "@feathersjs/vuex": "^4.0.1-pre.16",
NodeJS version: v14.16.1
Operating System: Ubuntu
Browser Version: chrome
I traced it to the addItems function in service-module-mutations
I think these statements are causing the performance issue.
state.ids.push(id);
state.keyedById[id] = item;
Somehow it takes a lot of time, maybe because of vue/vuex reactivity. Don't know exactly why.
A possible solution hereunder takes it to less then a second:
function addItems(state, items) {
const keyedById = {}
const stateIds = []
const { serverAlias, idField, tempIdField, modelName } = state;
const Model = _get(models, [serverAlias, modelName]);
const BaseModel = _get(models, [serverAlias, 'BaseModel']);
for (let item of items) {
console.log ("item " + item._id)
const id = getId(item, idField);
const isTemp = id === null || id === undefined;
// If the response contains a real id, remove isTemp
if (id != null) {
delete item.__isTemp;
}
if (Model && !(item instanceof BaseModel) && !(item instanceof Model)) {
item = new Model(item, { commit: false });
}
if (isTemp) {
let tempId = item[tempIdField];
if (tempId == null) {
tempId = assignTempId(state, item);
}
item.__isTemp = true;
state.tempsById[tempId] = item;
}
else {
// Only add the id if it's not already in the `ids` list.
if (!state.ids.includes(id) && !stateIds.includes(id)) {
stateIds.push(id)
//state.ids.push(id);
}
keyedById[id]=item
//state.keyedById[id] = item;
}
}
state.keyedById = {...state.keyedById,...keyedById}
state.ids = state.ids.concat(stateIds)
}
Metadata
Metadata
Assignees
Labels
No labels