DEV Community

Discussion on: Array inputs validation and the N+1 query problem in Laravel

Collapse
 
dydemin profile image
dydemin

Would it be a problem if statuses table contains huge amount of records?

In this solution all statuses are selected each time we need to validate input.
It may be better to limit statuses query result with ids from request.

Collapse
 
michaelvickersuk profile image
Michael

Great question, yes if you anticipate the statuses table containing lots of rows then some optimisation of the query will be beneficial. The same issue applies wherever the N+1 problem occurs, as even when using $model->with() or $model->load() if the tables being eager loaded have lots of rows or columns this could also lead to performance issues.

Your suggestion is a good one, an alternative approach might be to cache statuses and then refresh the cache whenever the statuses are changed, it all depends upon the table size and the use cases.