Two days, one idea, and the discipline to stop when it worked.
This is seed content. It is long enough to exercise the excerpt, the reading time, the contents list and the list views without pretending to be real writing.
Where it started#
Every project has a moment where the shortcut stops paying for itself. Ours arrived with a query nobody could explain, in a file nobody had opened in a year.
The cheapest code to maintain is the code you can read at a glance.
What we changed#
Three decisions, in the order we made them.
- One decision
- Another decision
- The thing we reverted
The part that mattered#
Writing it out by hand meant we could see the cost. See the approach for the longer version, or the PDO manual for the mechanics.
SELECT c.title, COUNT(*) AS comments
FROM content c
JOIN comments m ON m.content_id = c.id
GROUP BY c.id
ORDER BY comments DESC;What it cost#
| Approach | Lines | Queries |
|---|---|---|
| Before | 240 | 18 |
| After | 96 | 3 |
Would we do it again#
Yes, and sooner.
0 comments