Это видео недоступно.
Сожалеем об этом.

Laravel Code Review: Optimize Queries and Other Performance

Поделиться
HTML-код
  • Опубликовано: 24 июн 2023
  • Today I'm reviewing the Artisan command code that I received via email.
    Related video. Laravel: Be Careful with whereHas Performance in Eloquent • Laravel: Be Careful wi...
    - - - - -
    Support the channel by checking out my products:
    - My Laravel courses: laraveldaily.c...
    - Laravel QuickAdminPanel: quickadminpane...
    - Livewire Kit Components: livewirekit.com
    - - - - -
    Other places to follow:
    - My weekly Laravel newsletter: us11.campaign-...
    - My personal Twitter: / povilaskorop

Комментарии • 32

  • @codewithrex
    @codewithrex 6 месяцев назад +1

    In my opinion you could also use ->lazy() instead of ->get() when querying the users - it sacrifices a runs a little bit slower for huge memory savings.

  • @anesu6184
    @anesu6184 Год назад +2

    The only addition I would do is add pagination logic so that if I have many employees the command will continue working without any changes.

  • @jmyers2896
    @jmyers2896 11 месяцев назад +1

    It would be good to run explain on the raw sql queries and checking for any full table reads. Then add indexes as needed to optimize those queries.

  • @jcc5018
    @jcc5018 Год назад +7

    so your part about caching the date I would never have thought of. Mainly cause I haven't thought about caching at all as Im still trying the get the other parts figured out. But I always assumed I would eventually just set up caching for whole pages that dont have to change all that often. I never really considered caching small pieces of data like this for optimization. So if you dont already have a video on this, perhaps you could make one that could explain different scenarios in which various levels of caching would help optimize an application.

    • @LaravelDaily
      @LaravelDaily  Год назад +2

      Searched "caching" on the channel for you: www.youtube.com/@LaravelDaily/search?query=caching

    • @jcc5018
      @jcc5018 Год назад

      @@LaravelDaily Thanks, its not as easy to search individual channels on mobile, but I also am not really in need of the topic personally at this time, Just wanted to provide a suggestion since you have asked for video ideas before, and I know you cover topics in different ways at times as there are many different ways topics can be implemented. This video prompted a question I thought may be worth diving deeper into, so I offered the suggestion.
      But i'll "cache" the response for future reference. I've got to go figure out how to use google ad manager

    • @kingstalker
      @kingstalker Год назад

      Good quistion

    • @erikguillen6599
      @erikguillen6599 10 месяцев назад

      just learned bout it too

    • @nsejanvier
      @nsejanvier 4 месяца назад

      ​@@LaravelDaily I want laravel 11 VS Flutterwave

  • @ryiad2010
    @ryiad2010 20 дней назад

    This is very useful, thank you

  • @timothybelekollie6461
    @timothybelekollie6461 Год назад +1

    this is great sir, thanks for always enlightening us.

  • @longingheart77
    @longingheart77 Год назад

    I believe you can check if date is during the weekend via Carbon instance method

  • @DeepStreamBits
    @DeepStreamBits Год назад +2

    I only use model query if I actually want to get the model, otherwise I'm just doing a DB::table('***') query

  • @BinaryKitten
    @BinaryKitten Год назад +1

    With the query change, you'll also need to update the data side as shift end_at won't be on a relation.

  • @TrueWebDev
    @TrueWebDev Год назад +1

    Hi, here could be a refactoring issue, "attendances" is HasToMany relation, so join can produce more than one user entity and we will get extra items in result $data array, this can cause data inconsistency or something else.

    • @LaravelDaily
      @LaravelDaily  Год назад +1

      Technically, you're right. But I guess those extra items could be identified and filtered out with where() conditions.

  • @ZyronZA
    @ZyronZA Год назад +1

    Why is this doing DB access and business logic in one function? How will you write tests for that command if you cannot mock the Holiday:: and User:: object, or even the business logic? What's the purpose of Day::sunday->name if it already has the name "sunday"?

    • @LaravelDaily
      @LaravelDaily  Год назад +2

      Valid points, making this artisan command testable would mean a strong refactoring. Maybe you would want to perform it? I would gladly shoot a video about it.

    • @Theo-bz8kk
      @Theo-bz8kk Год назад

      You can still make feature tests for this command.

    • @ZyronZA
      @ZyronZA Год назад

      @@LaravelDaily Hey! I don't see the purpose a command having a test written for it as it's just to coordinate operations.
      My thinking here is the business logic should be in its own class and injected into the command constructor. Then the Holiday:: + User:: object are injected into the business logic class.
      A test is then written for the business logic class to lock down its functionality.

  • @junjunghasudungan1905
    @junjunghasudungan1905 9 месяцев назад

    Hello sir,
    User()->query()
    The Meaning is instence to model user for elequent?
    What a benefit to used?
    Thanks for education us with this video

    • @LaravelDaily
      @LaravelDaily  9 месяцев назад

      This video is the answer: ruclips.net/video/yviVaX7-wT4/видео.html

  • @bumblebity2902
    @bumblebity2902 Год назад

    Is it big "NO" to use DB queries in helper functions or should I cache daily for example to convert currency?

    • @LaravelDaily
      @LaravelDaily  Год назад

      It depends on the situation, there's no single answer.

  • @bc0078
    @bc0078 Год назад

    Very nice but shouldn't weekend be sunday and saturday?

  • @syracuse4612
    @syracuse4612 Год назад

    Nice🥰

  • @mohammedattar3628
    @mohammedattar3628 Год назад

    i need to email your sir

  • @-slash-7772
    @-slash-7772 Год назад

    Hi, I have a question about deleting "second degree relationships." Lets say I have a grandparent->children->grandchildren and when I delete a grandparent, my goal is to delete its children and grandchildren. I'm not sure if there is a good, standard solution, but here is ChatGPT's working solution:
    // Grandparent.php (the function is utilized in the GrandparentController.php when deleting)
    public function deleteWithRelated()
    {
    // Delete grandchildren
    $this->grandchildren()->each(function ($grandchild) {
    $grandchild->delete();
    });
    // Delete children
    $this->children()->each(function ($child) {
    // Delete children
    $child->delete();
    });
    // Finally, delete the grandparent
    $this->delete();
    }

    • @LaravelDaily
      @LaravelDaily  Год назад +1

      I would personally do it on the database level, in migrations: $table->foreignId()->constrained()->cascadeOnDelete();
      But if you don't have that in the database, then yeah, I guess ChatGPT solution is ok.

    • @LaravelDaily
      @LaravelDaily  Год назад

      Following up, I've just published this tutorial.
      Laravel Parent Children and Grandchildren Delete: Three Options
      laraveldaily.com/post/laravel-parent-children-grandchildren-delete-records