samedi 24 décembre 2016

Laravel 5.1 DB::table chunk for a Restful API and Angular.JS

Is there a way to chunk millions of records in a Restful API call?

I am using Angular.JS / Ionic for the client and have a restful API that works great with smaller number of records about 10,000. But my database has a couple of million records and if I make an api call to show all records it returns http Response Code 500. The reason I want to pull all the data is so that users can search the matching product using ng-model="query". On the client only 100 handpicked records will be displayed. I looked at the Laravel documentation and it suggests chunking the data. I tried the following code but I get the 500 http response code error. I am using mysql as the database. Eventually Iw ill be building a redis cache but to begin with I need to b able to fetch all the results.

$productlist = DB::table('productlist')->chunk(1000, $products) { foreach ($products as $product) {

    $productlist = array_merge($products, $product);
    }
    });     

 return $productlist;



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire