Parallelism with Angular 2

0

I need to insert 30,000 records in the device (in SQLite) through a file. But at the time of insertion, the application hangs. So I thought of creating an asynchronous service, but I do not know how to do this using Angular 2.

Code:

this._http.get('assets/fishes.sql').subscribe(data => {

    var queries = data.text().split(";");
    for (var i = 0; i < queries.length; i++) {
        var currentQuery = queries[i];
        this.populaFishes(db, currentQuery);
    }
});

How can I create a service that runs in background so that the application does not crash using Angular 2?

    
asked by anonymous 24.02.2017 / 15:39

1 answer

0

I think the best way to do this structure is to send those records in smaller amounts, since when you force that 30,000 insert to run, you allocate all that content in memory (keeping in mind that you are creating something for mobile).

The problem in question is not the Angular, but the processing capacity. You can have as an example of why not do this when we see the Facebook API. Regardless if you want a great mass of data, facebook will send you a limit of 5 thousand records.

Not only in angular but in any other language, a massive manipulation of data will require a great deal of processing and (obviously) a memory consumption, so you'd better do 30 times its function and give 1000 items entry per instead of running 1 time and inputting everything at the same time, not to mention that by using that way you can still pass on feedback to the customer of the progress of the processing (such as a loading bar ...)

    
28.09.2017 / 14:24