Тёмный
No video :(

Laravel Code Review: Optimize Queries and Other Performance 

Laravel Daily
Подписаться 143 тыс.
Просмотров 11 тыс.
50% 1

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

Опубликовано:

 

24 июн 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 32   
@codewithrex
@codewithrex 6 месяцев назад
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.
@jmyers2896
@jmyers2896 11 месяцев назад
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.
@anesu6184
@anesu6184 Год назад
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.
@jcc5018
@jcc5018 Год назад
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 Год назад
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
@timothybelekollie6461
@timothybelekollie6461 Год назад
this is great sir, thanks for always enlightening us.
@ryiad2010
@ryiad2010 20 дней назад
This is very useful, thank you
@longingheart77
@longingheart77 Год назад
I believe you can check if date is during the weekend via Carbon instance method
@DeepStreamBits
@DeepStreamBits Год назад
I only use model query if I actually want to get the model, otherwise I'm just doing a DB::table('***') query
@BinaryKitten
@BinaryKitten Год назад
With the query change, you'll also need to update the data side as shift end_at won't be on a relation.
@LaravelDaily
@LaravelDaily Год назад
Yes great point
@TrueWebDev
@TrueWebDev Год назад
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 Год назад
Technically, you're right. But I guess those extra items could be identified and filtered out with where() conditions.
@ZyronZA
@ZyronZA Год назад
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 Год назад
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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-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?
@LaravelDaily
@LaravelDaily Год назад
Not in all countries of the world
@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 Год назад
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
Далее
PHP For Beginners -  Complete Laracasts Course
10:44:12
Просмотров 129 тыс.
Вся Правда Про Хазяевов !
41:02
Просмотров 1,8 млн
Refactor "Senior" PHP Code with Early Returns
12:09
Просмотров 26 тыс.
Laravel's secret weapon: macros (watch me code)
23:46
Don't Use Polly in .NET Directly. Use this instead!
14:58
The Logging Everyone Should Be Using in .NET
15:34
Просмотров 57 тыс.
Livewire vs. Inertia
11:05
Просмотров 4 тыс.
Laravel + Livewire todo app (and so much more)
16:41
Просмотров 38 тыс.
Laravel Horizon: queue monitoring + configuration
14:54
Laravel Code Review: Why NOT Use Repository Pattern?
14:21
Svelte 5's Secret Weapon: Classes + Context
18:14
Просмотров 16 тыс.
Static Methods in Laravel/PHP: When and How?
10:39
Просмотров 17 тыс.