Parallelism with Angular 2

Asked

Viewed 108 times

0

I need to insert 30,000 records into the device (in Sqlite) through a file. But at the time of insertion, the application hangs. So I thought about creating an asynchronous service, but I don’t know how to do it 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 on background so that the application does not lock using Angular 2?

  • Do you plan to run this task more than once? Or just deploy? What exactly is the use case?

1 answer

0

I believe that the best way to do this structure is to send these records in smaller quantities, since when you force the execution of this insertion of 30,000, you allocate all this content in memory (bearing in mind that you are creating something for mobile).

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

Not only at the angular but in any other language, massive manipulation of data will require extensive processing and (obviously) memory consumption, so you better run your function 30 times and input 1000 items at a time than run 1 time and input everything at the same time, not to mention that, using this way, you can still pass to the customer a feedback of processing progress (as a load bar...)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.