Closed ThanhSonITNIC closed 5 months ago
after debug, i found this problem https://github.com/Lomkit/laravel-rest-api/blob/3e7667ef7dd84350931f02aebb597ced1c184fe4/src/Rules/SearchRules.php#L99-L143 this is a lot of data with size 92MB
Hello @ThanhSonITNIC,
Thanks for your contribution, if I understand well, in your case the problem is that the fields in the rules are taking a lot of memory ? How much resources do you have in your project ? I'll investigate also because a few weeks ago I decided to be aware about nested fields because in other places it took times to calculate 😄
I have 24 resources, each resource only 2 to 5 relations, and around 10 fields each resource this function generate many nested relation fields https://github.com/Lomkit/laravel-rest-api/blob/3e7667ef7dd84350931f02aebb597ced1c184fe4/src/Rules/SearchRules.php#L114 in some resources it throw error memory size exhausted this pull request https://github.com/Lomkit/laravel-rest-api/pull/100 can limit useable fields
@ThanhSonITNIC I can confirm on my side on a large project i went from 3.5 sec to 300ms on a search
Laravel Rest Api Version
2.4
Laravel Version
10
PHP Version
8.1
Database Driver & Version
mysql
Description
Filters query take a long time in both local and server
Steps To Reproduce
[POST] /api/products/search
[2024-01-22 03:09:28] local.DEBUG: select count() as aggregate from
products
whereseller_id
= ? and (products
.id
in (?, ?)) {"bindings":["1","1","2"],"time":1.99} [2024-01-22 03:09:28] local.DEBUG: select fromproducts
whereseller_id
= ? and (products
.id
in (?, ?)) order byproducts
.id
desc limit 50 offset 0 {"bindings":["1","1","2"],"time":0.76}[2024-01-22 03:10:53] local.DEBUG: select from
personal_access_tokens
wherepersonal_access_tokens
.id
= ? limit 1 {"bindings":["1"],"time":20.95} [2024-01-22 03:10:53] local.DEBUG: select fromusers
whereusers
.id
= ? limit 1 {"bindings":["1"],"time":0.66} [2024-01-22 03:10:53] local.DEBUG: updatepersonal_access_tokens
setlast_used_at
= ?,personal_access_tokens
.updated_at
= ? whereid
= ? {"bindings":["2024-01-22 03:10:53","2024-01-22 03:10:53",1],"time":3.55}[2024-01-22 03:10:54] local.DEBUG: select count() as aggregate from
products
whereseller_id
= ? {"bindings":["1"],"time":0.71} [2024-01-22 03:10:54] local.DEBUG: select fromproducts
whereseller_id
= ? order byproducts
.id
desc limit 50 offset 0 {"bindings":["1"],"time":0.66}