tegos
tegos

Ivan Mykhavko

@tegos

Software engineer

19 Posts 315 Views

  • No matching results...
  • Searching...

/ 255

Poll Options

Wrote a follow-up on my laravel-telescope-flusher package with real benchmark numbers. `telescope:clear` takes 2.5 hours on 1M entries and leaves 3 GB locked in your `.ibd` files, because InnoDB doesn't return disk after `DELETE`. The flush variant uses `TRUNCATE` + `OPTIMIZE TABLE`, finishes in 1.21 seconds, and actually gives the disk back.
dev.to/tegos/why-telescopeclear-is-slow-and-how-to-reclaim-disk-in-seconds-26of


Laravel's `whereDate('created_at', $day)` feels clean, but it secretly wraps the column in `DATE()` which kills the index on big tables.
Swap it for a `>= startOfDay()` / `< next day` range and MySQL can use the index again. Same trap hits `whereMonth`, `whereYear`, `whereDay` if the column is inside a function, assume the index is gone.

dev.to/tegos/laravel-wheredate-silently-kills-your-index-2lnf

16

`$fillable` doesn't know if it's the admin panel or the customer API calling `Order::create()` - so fields like `is_forced_processing` or `is_from_api` are equally "allowed" for everyone. This post explains why mass assignment breaks down in large Laravel projects and how the DTO + Action pattern fixes it.

dev.to/tegos/fillable-has-no-context-why-mass-assignment-breaks-down-at-scale-3lmj

24

Ever stared at a 50k row export and thought "are my enums slowing this down?"

I did. So I rewrote the whole thing to use pre-cached arrays instead of tryFrom() on every row, moved JSON decoding to raw SQL, and benchmarked both versions carefully.
Result? 16ms difference. Literally noise.

Turns out PHP 8.1 enums are singletons - same instance every time, no allocations, no GC pressure. Your real bottleneck is I/O and formatting, not enums.
Use tryFrom(), this is fine.
dev.to/tegos/php-enums-are-not-your-bottleneck-heres-proof-1887

44

Ever wonder why that trait seemed like a good idea until you needed to test it?
Traits in PHP look convenient at first, but they hide dependencies, break encapsulation, and make your code harder to understand.
I wrote about why I avoid traits and what works better: dependency injection, composition, and simple classes.
Real dependencies should be visible in the constructor, not burried in protected methods.
The rule is simple: if behavior can be extracted into a seperate object, it should be.
dev.to/tegos/why-i-avoid-php-traits-and-what-i-use-instead-1288

50