Optimize API Return Kilobytes, not only Eloquent

Поділитися
Вставка
  • Опубліковано 3 лют 2025

КОМЕНТАРІ • 20

  • @Krlos-n4k
    @Krlos-n4k 3 роки тому +8

    I was returning a big JSON column and I didn't know the impact of that until in the pilot test the query took like 5 seconds to get 360 records, from 14MB to 143Kb
    I didn't realize this until I got this video on my recommended
    Thanks sir

  • @joskolenberg
    @joskolenberg 5 років тому +4

    Thanks for another nice tutorial Povilas.
    Optimizing the return data is indeed important. However I prefer to use the Laravel-Jory package instead of Laravel's Resource classes because it let's you pick the fields and relations from the frontend. No need to set up a separate Resource class every time you need a different data structure to be returned.
    (yes, I'm biased. Wrote the package myself 😁)

  • @nabeelyousafpasha
    @nabeelyousafpasha 5 років тому +6

    Optimizing this way matters a lot. Thanks and Love from Pakistan.

  • @mikro63tv94
    @mikro63tv94 4 роки тому +2

    This is only affects the size of the response, but the speed is not because you are still doing select *, how about including only the columns you want to show in the API Response? how you will do that?
    Great info thanks.

    • @mikro63tv94
      @mikro63tv94 4 роки тому

      in the second parameter of paginate method. You can specify which columns you want to select.

  • @renwar
    @renwar 3 роки тому +1

    After one year youtube recommended it again for me with a question after some experience with large data and laravel resources.
    What to do when you need different type of columns in the same Model/table? Ex: Product Model, in some situations only barcode and name or with price or in other situations whole columns are required.

    • @renwar
      @renwar 3 роки тому

      I have called product model in Sale, in Purchase, and so on...

  • @nekozu_
    @nekozu_ 4 роки тому +1

    Thank you sir. This is really helpful for my big project.

  • @orkhanalikhanov
    @orkhanalikhanov 3 роки тому +3

    That's where GraphQL is really helpful. Did you use it ever? I never did tbh

  • @waseemusman421
    @waseemusman421 Рік тому

    Please must give me answer, M facing very slow laravel API response. i was thinking that may be database queries are not optimized. What i did is i created new route with closure function and just return empty response, just to check laravel response time. Unfortunately that empty response was also very slow, and it took almost 1100 ms. Plz guide me how to debug and what would be possible reasons for this

    • @LaravelDaily
      @LaravelDaily  Рік тому

      Something wrong with your web-server in general, then. It's impossible to blindly guess. Try non-Laravel project. Try non-API project. Find the reason.

  • @47Lancelot
    @47Lancelot 5 років тому +1

    noob question: why you use method ::collection but toArray is called?

    • @PovilasKorop
      @PovilasKorop 5 років тому

      If I understand your question correctly, you think there's a double work - return collection and array? In this case, toArray refers to formatting the array of fields, not array of User records. Not sure if it's clear.

    • @47Lancelot
      @47Lancelot 5 років тому

      Povilas Korop so he redefined method toArray which is called by get() ?

    • @PovilasKorop
      @PovilasKorop 5 років тому

      @@47Lancelot now thinking about it, maybe you're right and maybe I did mess up some of those parameters, although result seems correct. What would be your way of doing it?

    • @47Lancelot
      @47Lancelot 5 років тому

      Povilas Korop I’m just trying to understand the video, dude)

    • @PovilasKorop
      @PovilasKorop 5 років тому

      @@47Lancelot then I guess you should read more examples of API Resources and specifically collections: laravel.com/docs/5.8/eloquent-resources#resource-collections

  • @DevAmirull
    @DevAmirull Рік тому

    Thanks

  • @DanielŚmigiela
    @DanielŚmigiela 3 роки тому

    awesome