Faster Eloquent: Avoid Accessors with Foreach

  Рет қаралды 54,316

Laravel Daily

Laravel Daily

Күн бұрын

Пікірлер: 70
@gillesashley9314
@gillesashley9314 2 жыл бұрын
I believe this is by far the best laravel channel on KZbin. Correct me if I'm wrong.
@unarmedwombat
@unarmedwombat 3 жыл бұрын
Possibly the single most useful tip I've seen this year. Thanks Povilas.
@BsiennKhan
@BsiennKhan 3 жыл бұрын
All of this spesific talk was music for my ears. I love tips on performance tuning, not only performance wise, it also helps you to be a better architect or engineer by following patterns AND improving cognative skills for future projects.
@obikwelukyrian6848
@obikwelukyrian6848 3 жыл бұрын
Watching your videos has made me an optimization freak tbh. And I'm not complaining 😊
@Tooltrocity
@Tooltrocity 3 жыл бұрын
This is a great video, I love learning performance stuff like this. It's the nuts and bolts of a tool that people don't talk about often enough. Please make more videos like this!
@LeonelViera
@LeonelViera 3 жыл бұрын
Nice that you elaborate your thinking process
@irvingviveros9314
@irvingviveros9314 3 жыл бұрын
New video = instant like! Thank you!
@edsontomas8344
@edsontomas8344 Жыл бұрын
Keep dropping them gems. Thank you
@rafa.alcantara
@rafa.alcantara 3 жыл бұрын
Povilas GOOD JOB, getting better day after day, Thanks for your incredible amount of work!
@mikaelDzp
@mikaelDzp 7 ай бұрын
thank you! you deserve more views !
@natenatters
@natenatters 2 жыл бұрын
Nice! Also, like you said at the end about caching, sometimes thats the best solution. You can use the existing logic and set an identity column inside of the User updating model event, then you bypass the need for an accessor.
@jacquesmatike9289
@jacquesmatike9289 3 жыл бұрын
That's a huge optimization ! Thanks !!
@jamzykimani
@jamzykimani Жыл бұрын
Awesome video👏👏 this plus the laravel-news article feels like a level up for me... So much actionable knowledge!!!
@ChangeYourLifeForever
@ChangeYourLifeForever 3 жыл бұрын
WOOW very intersting , we need more of those videos plz ( explain for us the eager VS normal ) loading data
@sachinvishwakarma290
@sachinvishwakarma290 3 жыл бұрын
Great and very helpful all your laravel video thanks 👍
@abrpp
@abrpp 3 жыл бұрын
Always on point. Thank you!
@leydergananbueno5466
@leydergananbueno5466 3 жыл бұрын
Su canal es el mejor, he aprendido mucho de usted ¡muchas gracias! buen contenido
@intipontt7490
@intipontt7490 3 жыл бұрын
I'm sure there's a perfectly reasonable sql query that returns the same results. This is a perfect example of when NOT to use Eloquent.
@Khalyomede
@Khalyomede 3 жыл бұрын
I completely agree with you. I recently found out when using "with('relation')", Eloquent will not perform an inner or left join, it will make a second "select ... where parent_relation in (all ids of parent_relation)", which for me was counter intuitive at first, but in the end to be able to have such a powerful chainable language you need to make some tradeoffs I guess. It still does the job pretty well to have a readable code!
@sauerkrautlanguage
@sauerkrautlanguage 3 жыл бұрын
My first thought was to make a view in the DB lmao
@devendergupta_official
@devendergupta_official 3 жыл бұрын
A very good lesson!
@ahanafi-id
@ahanafi-id 3 жыл бұрын
Great Video, thanks
@mohammadrezaarab7890
@mohammadrezaarab7890 Жыл бұрын
It was really helpful. thanks
@Shez-dc3fn
@Shez-dc3fn 3 жыл бұрын
whats baffling me is he does select id from users but in attr he uses $this->name which i assume is an attr of that table.. :/ this name will always be null/empty since its not selected
@07Weka
@07Weka 3 жыл бұрын
He discussed and solved that in the video :/
@martinfeldman7340
@martinfeldman7340 2 жыл бұрын
How can I add this video to some permanent list ? This is beyond excellent. Thank you so much Povilas!
@shahsawoodshinwari
@shahsawoodshinwari 11 ай бұрын
When I have to choose between a method on eloquent and an accessor, i check if there is any query launched to db, if yes, then it is definetly not an accessor as accessors are loaded on model load, while methods don't.
@alexandrelima5886
@alexandrelima5886 3 жыл бұрын
Great approach! Thx
@jetferret
@jetferret 3 жыл бұрын
Thank you so much for this video. Fantastic example how Laravel devs abuse Models nowdays.
@martinlionel7487
@martinlionel7487 3 жыл бұрын
Good video. The most erreur is : use trust orm and don't know how bdd work
@murr3540
@murr3540 3 жыл бұрын
I have an issue, i don't know if its laravel or db issues, but if idle for a certain period of time and tried to retrieve data on the database I got like 1.5k to 3k ms , but on 3rd or 4th call its like on for 400ms, same records it was same records, and I'm using mongodb.
@TimvandenBelt
@TimvandenBelt 3 жыл бұрын
Once again, a great and educational video! Thanks! However, a small suggestion if you wish to push performance and be more strict with how the app deals with variables (less unexpected behaviour): use identical comparison (===) where possible. I noticed that for several comparisons where it should always be a comparison between two integers, a lossy equation (==) is used.
@koldovalnya
@koldovalnya 3 жыл бұрын
Thanks 4 tutorial
@MrFa321
@MrFa321 3 жыл бұрын
Which server are you using in mac for running laravel applications? Like xampp or any other?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Laravel valet
@darkmode404
@darkmode404 3 жыл бұрын
Thank you!
@f00n168
@f00n168 3 жыл бұрын
Thank you 🙏🏻
@iamriwash7943
@iamriwash7943 3 жыл бұрын
finally i got what i looking for ( thanks)😊
@AbrarAhmad-mz8vl
@AbrarAhmad-mz8vl 3 жыл бұрын
So basically it is issues with queries itself, not with accessor. Is it? If I'm using just get modify date format will it perform bad too?
@hasanbaig1540
@hasanbaig1540 2 жыл бұрын
That's really important topic to follow in development. If you have the right tool then task seems more interesting to do. I haven't found the name of this debugging tool in description please share the link.
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Composer require barryvdh/laravel-debugbar, also Laravel telescope and Spatie Rsy - those are the tools
@demeja16
@demeja16 3 жыл бұрын
It is so cool, thank you for this video!:)
@technical157
@technical157 3 жыл бұрын
very interesting. thx
@MrJoboski
@MrJoboski 2 жыл бұрын
Amazing!
@GergelyCsermely
@GergelyCsermely 3 жыл бұрын
Excellent. Could You please link the Ray setup video? If I'm not mistaken You have a nice presentation.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
kzbin.info/www/bejne/pGXTfquvdr2Yp7s
@GergelyCsermely
@GergelyCsermely 3 жыл бұрын
@@LaravelDaily Thanks
@mohammadalisadeghi-q4j
@mohammadalisadeghi-q4j 5 ай бұрын
awesome ❤
@p30mehrdad
@p30mehrdad 3 жыл бұрын
Thanks
@ricko13
@ricko13 3 жыл бұрын
nuostabus, plojimai!
@mikegodz
@mikegodz 3 жыл бұрын
Great video! Sometimes there's no reason not to do what the DB is designed to do. On the other hand, there are situation like the following: suppose you have a Posts/Comments project, and you want to show all the comments of a user, but visually divided by post. This is not a "SQL-grouping", cause you don't need to use some aggregate function on the data, but just to have them organized by post. On your opinion, what's a good way to handle these data? I am going with a foreach and an associative array, but doesn't feel right...
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Why is it not SQL grouping? When doing the query, you group by post_id, and then in the Blade do foreach ($post) -> foreach ($post->comments) etc.
@mikegodz
@mikegodz 3 жыл бұрын
Because when you group by post_id (in SQL syntax) you aggregate the results using count, sum, etc. That's what I mean with "SQL grouping". Are you referring to using the groupBy function of Laravel?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Yes I thought so, actually thinking about it, it's best to group in collection then, so something like ->get()->keyBy(post_id) or something, don't remember the exact collection method.
@mikegodz
@mikegodz 3 жыл бұрын
@@LaravelDaily Didn't know about the keyBy method. I'll dive into it, thanks!
@hungrybox2100
@hungrybox2100 3 жыл бұрын
Can you please make a video on recursive function when category needs to be display in hierarchy? Because it causes performance problem
@LaravelDaily
@LaravelDaily 3 жыл бұрын
This video should help: kzbin.info/www/bejne/a6SQkIaki9FgZ8k
@kkamarada4
@kkamarada4 3 жыл бұрын
Nice work o/
@novichkovv
@novichkovv 2 жыл бұрын
Why don't you use laravel ide helper? My perfectionist eyes are bleeding seeing those inspector warnings. But besides aesthetic aspect, ide helper really improves the quality of code by avoiding typos and development speed by autocomplete. I always try to make each php file having green inspector mark, thus, especially if you use type hints, return types and declare strict, green mark says that everything here is correct and you need to pay attention only to the logic
@teb1687
@teb1687 3 жыл бұрын
why are comments being deleted?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I haven't deleted any comments, except for obvious spam bots
@teb1687
@teb1687 3 жыл бұрын
@@LaravelDaily ok must be some yt issue
@alexaverkiyev9099
@alexaverkiyev9099 3 жыл бұрын
The approach of original code was breaking single responsibility principle and was wrong from the very beginning
@kieronwiltshire1701
@kieronwiltshire1701 2 жыл бұрын
Thing is... 700ms is ridiculous for a "production" ready framework
@gianfrancobriones
@gianfrancobriones 3 жыл бұрын
I am guilty
@david-kahly
@david-kahly 2 жыл бұрын
not a good example at all. the code and schema should be refactored.
@dokumentalny
@dokumentalny Жыл бұрын
Names of this metod is a straight from hell 😅 is_ghost - rally?!?
@devMoemen
@devMoemen 2 жыл бұрын
very good thanks
Eloquent Performance Challenge: My Solution Version
9:57
Laravel Daily
Рет қаралды 19 М.
Laravel Junior Code Review: 12 Tips on Everything
15:30
Laravel Daily
Рет қаралды 75 М.
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 7 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 19 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 84 МЛН
Junior Code Review: Laravel Routes, Middleware, Validation and more
19:57
Laravel + Livewire todo app (and so much more)
16:41
Aaron Francis
Рет қаралды 51 М.
Advent of Neovim: Why Neovim?
10:21
TJ DeVries
Рет қаралды 28 М.
“use cache” NextJS’s latest take on data caching
17:27
Jack Herrington
Рет қаралды 9 М.
Laravel: Create Public API with Cache and Rate Limits
12:18
Laravel Daily
Рет қаралды 46 М.
What’s Up with Laravel? It’s Everywhere, and Here’s Why!
6:22
Optimizing Eloquent: Running Out Of Memory?
6:11
Laravel Daily
Рет қаралды 43 М.
Eloquent or Query Builder: When to Use Which?
5:48
Laravel Daily
Рет қаралды 88 М.
The secret behind FrankenPHP: Will it revolutionize PHP?
12:40
Chris Fidao
Рет қаралды 43 М.
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 7 МЛН