theblack68's avatar

Laravel Debugbar (MODEL)

Hi ...I'm use a debugbar in a project and I Work with datatables (in blade I do a foreach for iterate the collection)

I have see that in the model load:

51 App\Models\Role

52 App\Models\User

I asked myself ... but if I retrieve thousands of records the model (example will mark 6000) does it affect system resources?

Am I wrong something?

0 likes
6 replies
tykus's avatar

if I retrieve thousands of records the model (example will mark 6000) does it affect system resources?

Yes, every hydrated model instance requires some memory; so 6000 instances requires ~6000x; this will not be all of the memory used by the application in serving that request, but it will contribute to the total.

Generally, if you are getting that many records, it is for a report, and then it can benefit you to drop down to the query builder to generate the data rather than hydrating models.

theblack68's avatar

@tykus thanks for response ...I'm pretty new with Laravel ... what should I do about it since I work with Datatables? Server Side?

tykus's avatar

Does your datatable need 6000 records in a single view; are you using server-side pagination at all?

theblack68's avatar

No @tykus I don't need all the records at once ... pagination does it directly datatables.

tykus's avatar
tykus
Best Answer
Level 104

pagination does it directly datatables.

If you mean that Datatables handles pagination on the client side, then yes, you do need all of the records from the server in the first request. However, you generally can setup Datatables to fetch only the current page, and then make subsequent requests as the user pages, filters, searches etc.

theblack68's avatar

Thanks I will look for some resource to read ... I offer a virtual beer;)

Please or to participate in this conversation.