Code Review: Optimize Seeds and Eloquent Queries

  Рет қаралды 12,345

Laravel Daily

Laravel Daily

Күн бұрын

Пікірлер
@faradtech
@faradtech Жыл бұрын
thank you for professional courses 💯💯
@norbertocammayo2334
@norbertocammayo2334 4 жыл бұрын
IMO you are one of the best laravel teacher. Keep it up.
@tlita93
@tlita93 4 жыл бұрын
Very interesting topic - seeders. I had an issue where I needed to seed content of about 30k text files to DB, which are just over text field limit and have to be mediumtext fields. It takes a solid amount of time, about a couple of minutes. I think it's due to using PHP's file_get_conent to read the file and write it's text to a field. Tho I'm not aware it can be done differently. Really great video sir. Your choice of topics always amazes me with uniqueness and usefulness, compared to a lot bigger channels, objectively speaking. Cheers
@kelvezu1585
@kelvezu1585 4 жыл бұрын
Your daily contents are awesome.
@kerolesmonsef4179
@kerolesmonsef4179 4 жыл бұрын
Also there is a faster way . To store the seeder data as a bulk of records instead of singular . By using query builder instead of eloquent
@AtiqSamtia
@AtiqSamtia 4 жыл бұрын
But the eloquent way is mostly better because it can run events & observers for any extra logic in the application and produce consistent data.
@kerolesmonsef4179
@kerolesmonsef4179 4 жыл бұрын
@@AtiqSamtia Offcourse but you will pay the price ( slowness )
@steveag8018
@steveag8018 2 жыл бұрын
learnt smth new today
@l.mu.433
@l.mu.433 4 жыл бұрын
Man, You're the Best! Thanks a lot!!
@Shez-dc3fn
@Shez-dc3fn 4 жыл бұрын
one thing to note is that you dont have to remove the user/book id from review factory even if we use your way. because laravel will use your way and ignore user/book id in review fact. reason is that maybe somewhere else (i.e. in tests) u might want to create a review row with random book/user..
@usherkadio3861
@usherkadio3861 4 жыл бұрын
Very helpful like always ...thanks a lot
@msdeav
@msdeav 2 жыл бұрын
thank you...
@codewithtee
@codewithtee 4 жыл бұрын
Very helpful, Thank you very much 🙂
@Pavelbrov
@Pavelbrov Жыл бұрын
5:09 - shouldn't we check in books is it confirmed or not as it was in original code on 4:56?
@GergelyCsermely
@GergelyCsermely 4 жыл бұрын
Very good, thanks
@fcorsair
@fcorsair 4 жыл бұрын
Grear video! I wonder if using Builder instead of eloquent world improve seeding performance more... could it be a good solution?
@PovilasKorop
@PovilasKorop 4 жыл бұрын
Yes, you are right, should be a bit faster.
@syracuse4612
@syracuse4612 Жыл бұрын
it's really cool
@TundeAwopegba
@TundeAwopegba 4 жыл бұрын
Can you check for the memory consumed as well
@paulfontaine7819
@paulfontaine7819 4 жыл бұрын
In my experience, using SQLite, when inserting many records, performance can be significantly improved by wrapping (chunks of) inserts or updates in a DB transaction. Do seeders do that for you?
@LaravelDaily
@LaravelDaily 4 жыл бұрын
In this example, I haven't implemented transactions and DB facade instead of Eloquent models, that may also speed up a bit, but not by much, I think.
@paulfontaine7819
@paulfontaine7819 4 жыл бұрын
@@LaravelDaily just two statements around the rest for me provides sometimes 80% performance gain DB::beginTransaction(); // normal eloquent stuff with many small database writes DB::commit();
@TsA1ex
@TsA1ex 4 жыл бұрын
Why you getting all() huge data, if use only 'id'. Try User::pluck('id') instead of User::all()
@LaravelDaily
@LaravelDaily 4 жыл бұрын
Yes, you're right, but I tested it, and in my case, the impact wasn't big, only 0.05s.
@legato0
@legato0 4 жыл бұрын
Useful tip. With extended tables, it will matter.
@lucianohanna1009
@lucianohanna1009 2 жыл бұрын
@@LaravelDaily What about RAM?
@bestsolution794
@bestsolution794 4 жыл бұрын
Thank you . Can you please make 1 to 1 chat system or support system
@LaravelDaily
@LaravelDaily 4 жыл бұрын
Here's a good article about it: modestasv.com/chat-with-laravel-pusher-and-socket-io-at-your-command/
@Remls
@Remls 4 жыл бұрын
Is it possible to see the GenresTableSeeder class?
@LaravelDaily
@LaravelDaily 4 жыл бұрын
Here's the shortened version: class GenresTableSeeder extends Seeder { public function run() { $genres = [ [ 'name' => 'Classic', 'description' => 'Fiction that has become part of an accepted literary canon, widely taught in schools', ], [ 'name' => 'Crime/detective', 'description' => 'Fiction about a crime, how the criminal gets caught and serves time, and the repercussions of the crime', ], [ 'name' => 'Epic', 'description' => 'A genre of narrative poetry in a time before history about extraordinary feats that involve religious underpinnings and themes.', ], // ... More genres ]; Genre::insert($genres); } }
@alex_nita
@alex_nita 4 жыл бұрын
Stupid question - what theme are you using for PHPStorm?
@bumblebity2902
@bumblebity2902 4 жыл бұрын
Material dark maybe he used.
@Minepuffik
@Minepuffik 4 жыл бұрын
@@bumblebity2902 Yes it is Material Darker,
@AtiqSamtia
@AtiqSamtia 4 жыл бұрын
What if we don't load all users or genres when we know there would be exactly 100 records and simply use 1 to 100 random int for user_id. It'll save a lot of memory usage & processing. Also, seeders are run mostly on a fresh migrated database and very controlled environment possibility of that record not existing is very low.
@LaravelDaily
@LaravelDaily 4 жыл бұрын
Yes it would work based on those assumptions. But you never know who would work with your code in the future and whether they would assume the same things.
Code Review: Route Groups - User/Admin, Controller Names(paces)
11:20
Junior Code Review: Better Routes, CRUDs and Validation
17:58
Laravel Daily
Рет қаралды 61 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Framer Update: Zooming, Layout, and more
2:04
Framer
Рет қаралды 4,8 М.
BIG News From Laracon EU 2025: My Opinions
14:15
Laravel Daily
Рет қаралды 6 М.
Laravel Validation: 12 Less-Known Tips in 13 Minutes
13:11
Laravel Daily
Рет қаралды 38 М.
👽 90s PC #gaming 💾 LIVE!
PC USER 486
Рет қаралды 140
Junior Code Review: Laravel Routes, Middleware, Validation and more
19:57
Junior Code Review: Simple Laravel API - in 5 Different Ways
9:34
Laravel Daily
Рет қаралды 78 М.