1

I have a question about proper or recommended way of loading a lot of data from database. I have Laravel 5.4 project with Vue.js 2.0. I need display employees table from database on a page. On client Vue component is used for requesting this data with promise and build grid with vue-tables-2.

The problem in case that i can't find proper way for logic. There is already 50 000+ records and will be more. So using Employees::all() is really bad idea. Data is requested with axios from api url. And there is no possibility of using reddis or memcached. Looks like i need some kind of lazy loading post request from client and maybe with Laravel pagination. I will request first part of data and make next request to paginator with next post... and will have spam of requests.

If i will use default caching mechanism i don't understand how to build logic of caching, how to detect that model was changed and cache require rebuilding.

Maybe there is a way to organize lazy loading of data with dynamically add it into table and if user start search or filter before loading finished make request to server for direct database search. But again in this case possibly i will have a lot of database requests.

So question is - maybe there is a recommended way for organization stuff like this ?

Matanya
  • 6,233
  • 9
  • 47
  • 80
Artem Zinoviev
  • 869
  • 12
  • 32
  • I guess pagination + filter search/query hitting the database seems pretty much the way to go. Maybe treating the searchResults separately from the actual data would work as a caching mechanism. In the meaning that searching won't "delete/override" the actual(already) loaded data. But I am quite sure that's something not native to Vue, should be your call in how to do it. Good luck – Cassio Cabral Feb 10 '17 at 13:32
  • I'm not familiar to laravel, but as @cassioscabral says, a proper way to reduce load should be to use pagination, additional to this, you could use server side rendering to show first page as soon as possible – AldoRomo88 Feb 10 '17 at 14:57
  • @AldoRomo88 correct me if i'm wrong, but there is no way to use SSR in php application. And problem was that i need full data set on client, not paginated, but this will be changed i think. in any case i must separate request because a lot of records in one query result can cause a problem. Not sure that pagination is good here, i think about separating query result with middleware and ->limit(), ->offset() methods. Already implement caching and raising event on model change for flush() cache. Search and filter will be implemented on server side. Hope it will work. – Artem Zinoviev Feb 10 '17 at 16:41
  • @ArtemZinoviev my bad, I'm neither familiar to php. After googling it seems a little more complicated than my initial thought. I'm sorry. The question that remains me is, why do you need to show 50,000+ rows on screen? If user can filter that records, that filtering must to be done on server side (ideally on db) to avoid sending huge amount of data over the wire, yes, you will have more requests but them will be cheaper – AldoRomo88 Feb 10 '17 at 19:17
  • @AldoRomo88 yes thanks, now i see that i need implement filtering and searching on server side. I was just try to use client side plugin for vue.js vue-table which already have search, filtering, pagination and other functionality from the box and ever hidden inside paginator data can be used for searching, but looks like it useful only for small set of data and in my case this must be done on server or db. – Artem Zinoviev Feb 11 '17 at 06:51

0 Answers0