Blog

Thoughts on software engineering, web development, and technology

S
Sam Lee

The Day I Finally Used EXPLAIN ANALYZE in Production

A cache clear exposed a slow analytics query, and EXPLAIN ANALYZE finally showed exactly where the time was going

Mar 12, 2026·PostgreSQL
S
Sam Lee

Why Relationship Records Weren't Being Created

A missing relationship record turned out to be a three-layer bug involving dropped metadata, the wrong read path, and a callback that was too narrow

Mar 02, 2026·Ruby on Rails
S
Sam Lee

Why One Dashboard Page Kept 502-ing

A dashboard page kept timing out because one eager-loading call was pulling 156K records into memory for no reason

Feb 09, 2026·Ruby on Rails
S
Sam Lee

The XSS Concern That Wasn't

A code review comment that looked like XSS turned into a useful reminder about ERB escaping and attacker-controlled input

Feb 07, 2026·Ruby on Rails
S
Sam Lee

Flash vs Flash.now: The Rails Gotcha That Finally Made Sense

A simple way to remember when to use flash and when to use flash.now in Rails

Feb 05, 2026·Ruby on Rails
S
Sam Lee

Two Practical Lessons I Picked Up Building an LTI Integration

A small LTI integration turned into two useful lessons: when to use Stimulus over Turbo, and why exists? is better than find_by for boolean checks

Feb 03, 2026·LTI
S
Sam Lee

That Time I Fixed a Sneaky N+1 Query in Grade Calculations

How I reduced 40+ database queries to just 5 by fixing N+1 issues in grade calculations

Jan 30, 2026·ruby
S
Sam Lee

ActiveRecord has_many Joins, DISTINCT, and When ORDER BY Needs a Subquery

Joining has_many multiplies parent rows; DISTINCT dedupes them. In PostgreSQL, DISTINCT plus ORDER BY on joined columns can error—wrap the deduped set in a subquery, then join and order on the outside.

Nov 26, 2025·Ruby on Rails
S
Sam Lee

ActiveRecord DISTINCT ORDER BY Error in PostgreSQL and Why a Subquery Fixes It

Seeing `for SELECT DISTINCT, ORDER BY expressions must appear in select list` in PostgreSQL? In ActiveRecord, a `has_many` join can require `DISTINCT`, but ordering by joined columns may need a subquery with `from(subquery, :alias)`.

Oct 15, 2025·Ruby on Rails
S
Sam Lee

Concurrent Indexes, Statement Timeouts, and When Migrations Stop Being “Deterministic”

Adding a column and a concurrent index on a huge table: the column landed, the index timed out under migration limits. disable_ddl_transaction!, statement_timeout reset, and idempotent add_column/add_index let a redeploy finish what the first run started.

May 23, 2025·Ruby on Rails

Built by Sam Lee with

 ♥