Blog

Thoughts on software engineering, web development, and technology

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

 ♥