Best Practice Question
The situation:
Using Angularfir2 I am trying to find the best way to check which, if any, of a list of items that I have stored locally exist within my Firebase database. This is considering that I have a very large amount of data in my Firebase database (in this example 100k + entries but could be well over 1M) and a good deal of entries locally (in this example 200 + however it could be over 1000)
So here is an example of the Firebase database:
"project-1234": [
{
"animals" : {
"1" : {
"animal" : "aardvark"
},
...
"100001" : {
"animal" : "zebra"
}
}
}
]
And here is an example of the json data stored locally:
[
{"my_id"=1, "fb_id"=346, "animal"="bear"},
...
{"my_id"=201, "fb_id"=45663, "animal"="water buffalo"}
]
Now I understand that I could simply loop over each item and then make an Angularfire2 "object" call (or even an http.get) in order to see if the item exists in the database:
this.data = [{...},...,{...}]; // local json data
for (let i in this.data) {
this.fbData.object('animals\' + this.data[i].fb_id).subscribe(dataObj => {
if (dataObj != null){
console.log('There is a : ', this.data[i].animal);
}
});
}
or
this.data = [{...},...,{...}]; // local json data
for (let i in this.data) {
let url = 'https://project-1234.firebaseio.com/animals/' + this.data[i].fb_id + '.json';
this.http.get(url).map(res => res.json()).subscribe((dataObj) => {
if (dataObj != null){
console.log('There is a : ', this.data[i].animal);
}
})
}
Question:
Although this is the only way I can think of to achieve my goal, even to my intermediate understanding this seems a little labor intensive not to mention slow and getting slower the more records are held locally; so I am wondering if there was a better solution out there or a best practice that can be used in a case such as this?
Many thanks in advance for any help/suggestions.