Performance Issue + feature request
pritamsoni-hsr opened this issue · 2 comments
Describe the bug
Running into performance issues when trying to update and add data frequently.
To Reproduce
Steps to reproduce the behaviour:
after fetching a list of dictionary, I need to store that list and update the dictionary if key is present multiple time times in the list. I'm facing performance issue. I can do something similar to bulk create/update.
here is a code snippet.
Expected behavior
A clear and concise description of what you expected to happen.
Code should be slow like storing every single value, then reading from the database and then updating it, but instead it is skipping all the values.
Screenshots
If applicable, add screenshots to help explain your problem.
As you can in this, first date is the key, 1st line is the previous value, 2nd line is the new value, when the same key is present, it should update the dict, but instead it is using the same.
Desktop (please complete the following information):
- OS: [Mac OS Catalina 10.15.6]
- Browser [safari]
- Version [e.g. 13.1]
Smartphone (please complete the following information):
- Device: [iPhone11, ]
- OS: [iOS13.6]
Additional context
Add any other context about the problem here.
Any plan for adding update, bulk update and bulk create queries?
@pritamsoni-hsr first thanks for using the plugin. I just do not really understand what you want to achieve,
as said in the doc it is a key-value pair storage for simple data of type string only
i assume that your response object is of type {timestamp: "2020-08-10",value:{key:93, value:"medium"}}
so the use of store.setItem should be async store.setItem("2020-08-10",JSON.stringify({key:93, value:"medium"})
What i do not understand is if you want to replace the value for a timestamp or if you want to add the new value to the old one
so it could be
response.forEach(async (element) => {
let key = element["key"];
let value = element["value"];
let obj = {key, value};
await store.getItem(element["timestamp"]).then((data) => async
console.log(element['timestamp'], data, { ...obj });
await store.setItem(element["timestamp"], JSON.stringify({ ...obj }));
});
});
this is working find
or
response.forEach(async (element) => {
let key = element["key"];
let value = element["value"];
let obj = {key, value};
await store.getItem(element["timestamp"]).then((data) => async
console.log(element['timestamp'], data, { ...obj });
await store.setItem(element["timestamp"], JSON.stringify([data,{ ...obj }]));
});
});
which is also working fine
hope this clarify
My bad I wasn't deconstructing the objects properly, and about the string thing, JSON.parse
and JSON.stringify
can be added to the base wrapper class, so devs never have to worry about datatype and parsing or storing it.
Storing in the array (like your second snippet) would increase the time complexity, and will make code ugly.
Thanks