I'm starting with a large array containing nested objects (~34,000 items), and I'm polling every 5 seconds, receiving updates to the array (generally 2-3 updates at a time) and the new array only contains items that have changed (so for example, if only 3 items changed, I only get those 3 items in my updated array.)
I tried the following using underscore, but it takes up to 9 seconds, I need like a second or less.
getUniqueUnion(new, old) {
return uniq(union(new, old), false, function(item) {
return item.info.id;
});
}
Anyone have a suggestion for a fast approach? If it helps, the unique key would be info.id, and the only change I'm really looking to detect (reason I need to update the item) is if the inStock value changes. In other words, if the inStock value hasn't changed, I dont need to make any update to that array item.
Example arrays:
const originalData = [
{
info: {
id: 1
},
moreInfo: {
name: 'hamburger',
inStock: true
}
},
... // 33,999 more
]
const updatedData = [
{
info: {
id: 1
},
moreInfo: {
name: 'hamburger',
inStock: false
}
},
... // maybe 2 more
]
So the final array would include the first item to have moreInfo.inStock === false
idof the entry you need to update you should look for thatidthen update only that entry instead of re-writing the entire arrayoriginalData. You get theupdatedDataby polling. Now, you want to update the data inoriginalDatabase on new data fromupdatedData. Is that right?