Performance: Factory definitions
MEDIUM IMPACT
Factory definitions affect the speed of database seeding and test data generation, impacting initial load and test execution time.
<?php use App\Models\User; User::factory()->count(1000)->create(); // Laravel batches inserts internally, reducing query count and speeding up seeding.
<?php use App\Models\User; for ($i = 0; $i < 1000; $i++) { User::factory()->create(); } // Each user triggers separate insert queries without batching or optimization.
| Pattern | Database Queries | Execution Time | Memory Usage | Verdict |
|---|---|---|---|---|
| Single insert per factory instance | 1000 queries for 1000 items | High (seconds) | Moderate | [X] Bad |
| Batch insert with Laravel factory | 1-5 queries for 1000 items | Low (milliseconds) | Low | [OK] Good |