The ceiling is a thousand rows

A comment beside the member totals names their ceiling: tens of thousands of sets, and then it gets slow. The query under it has no range, and the API it calls stops at a thousand rows without saying so.

3 min readMicroGym · History stage

Open a member on the platform and the page shows what they have done: sessions attended, workouts logged, sets, total reps, total volume, the date of their latest session. Every number comes from one function. It asks the database for the member's sessions and for every set they have ever recorded, then adds them up in the browser.

A ceiling, written down

Adding up in the browser was a choice, and the function says so. The comment above it, added on 24 July 2026, gives the reason and the limit in three lines: the query layer has no sum or count over a filtered join, a member has tens of rows, and the work should move to a view or a database function if a member ever has tens of thousands. The anatomy row quoted that comment and called it a ceiling named rather than hidden. It is the right instinct. It names the wrong ceiling.

Where the ceiling actually is

The set query selects reps and weight where the member matches, and stops there. No range, no limit, no count. The hosted database API this platform calls has a maximum number of rows per request, and its default is one thousand. A request that matches more does not fail. It returns a thousand of them, in no stated order, with no error, and the code reads that as everything. The repository holds no configuration for that setting, so I read it from the live project on 11 November 2026: it is the default. The ceiling is not slowness at tens of thousands of sets. It is a wrong answer at one thousand and one.

A thousand is closer than it sounds. A set here is a row per member, per movement, per round. A session of six movements over three rounds writes eighteen of them, so a member who trains that way reaches a thousand in their fifty-sixth session, about a year of weekly visits. From then on Sets Logged reads exactly 1,000 and stays there, and total reps and total volume are sums over whichever thousand came back, while the member keeps training. No one is there yet: on the same day the most sets any member had recorded was 29. Nothing on the page would look broken. A round number is the only clue, and nobody reads a round number as a clue.

Why the comment missed it

The comment reasons about cost: how much work the browser does as the list grows. That is the failure a person expects, because it is the one they would feel. The row cap is not a cost. It is a contract the API keeps quietly, and it turns a slow page into a fast, confident, wrong one. The same file's session query has the same shape, though a member is unlikely to attend a thousand sessions. The page also asks for the totals twice, once when the page loads and again each time the metrics tab opens. The overview shows only two session fields, so the first request pulls every set row for nothing.

What would fix it

The comment already names the fix: a view or a database function that sums on the server and returns one row. That removes the cap, the transfer and the browser arithmetic at once, and it is a small migration with an obvious rollback. Short of that, asking for an exact count alongside the rows would at least let the page notice when it has been handed less than everything. Neither is in the code today. The row above now says where the ceiling is.

Why it belongs on this page

Naming a ceiling is still better than hiding one, and this note does not take that back. But a named ceiling is a claim, and it needs the same check as any other: read the line it sits on and ask what actually stops first. Here the answer was not the database or the browser. It was a default in a settings page, one layer away from the code, that the comment never mentions because nobody had to think about it at tens of rows.

More notes
  • The webhook that credits twiceA payment processor delivers every result at least once. The interesting engineering is in what happens when your side fails halfway through.
  • A ledger you can edit from a route handler is not a ledgerWhy every movement of value on the payments platform goes through a Postgres function, and what it costs to keep it that way.
  • Four rows that were not theirsHardening multi-tenant row-level security in four reversible phases, verified by impersonating a member and counting what they could see.
  • The bug inside the fixA payout race, the fix for it, the bug inside that fix, and why it is the best argument I have for one person owning the whole path.
  • The sale that arrives with no referrerA creator shares a link on Instagram, the buyer taps it, installs the app and purchases. Nothing in that chain carries the creator's name across. Here is what does.
  • The minimum that belongs to someone elseHeld commissions are released to creators once a brand's payout minimum is met. Group the money by creator, the obvious way, and one brand's minimum ends up holding another brand's money.
  • The commission that must not mint twiceA buyer pays and the platform owes a creator a commission. Between those two facts sit a colluding pair, a call that arrives twice, and a cart with three items on one payment.
  • The rule that has to be written twiceFirestore security rules do not cascade to subcollections. Forget that in one place and a single query returns every private message on the platform.
  • Thirty days in the ledgerSplitting a payment at charge time is simpler and wrong: a refund after the creator is paid is a clawback nobody enjoys. Holding the money creates a different set of problems, and each piece of machinery around the hold answers one of them.
  • Arbitrary but consistentA gym's assessment answers become rules that swap an exercise for a member before a session. Two rules can disagree about the same movement. The code says who wins, and the comment admits how.
  • The number that ducked every thresholdA deposit arrives from a browser carrying two numbers. The platform scored one of them and charged the other, and every limit it had was measuring the wrong figure.
  • The second one tells you the shapeHigh-risk merchants get dropped by processors, so the platform cannot be welded to one. The interface that makes a processor swappable could not be designed before the second one existed.
  • A key you did not makeA device fingerprint is a hash the browser computes and the server has to take on faith. The useful question is not whether to trust it, but what a server does once it accepts that it cannot.
  • The template never learns your nameA trainer builds a workout once and runs it for a room of people who are not the same. The data model that survived is three tables with a one-way street between them, and the model it replaced was the obvious one.
  • The copy that heals itselfA marketplace that sells a brand's products keeps a copy of the brand's store. The same codebase keeps that copy two different ways, and the slower one is the one that is right by morning.
  • The ledger was rightA team sale splits one commission between two people. The split was recorded correctly everywhere a person could look, and the code that sent the money would have paid the wrong one.
  • Zero was not a ceilingA creator can write their own commission rate, so the server caps it at what the brand agreed to. For most of the catalogue the cap never ran, because those products carried no commission of their own.
  • Smaller than it wasOn 27 September the gym's movement library lost 4,724 lines and gained one field. What came out was a theory of how movements relate. What replaced it was a trainer writing the relation down.
  • The toast that could not fireA trainer taps Mark All and the whole room's round is recorded. From October 2025, if every one of those saves failed, the app said nothing, because a failed save and a deliberate skip had become the same value.
  • Spent, but not on anythingEvery deposit required a texted code, and each code could be spent once. Nothing recorded which deposit spent it, so the dispute packet that cited those codes was counting texts, not approvals. Now each spent code carries the checkout it approved.
  • No exceptions notedThe platform could generate a certificate of its own controls for underwriters, and every result in it was the same fixed string. Re-reading it for this page found that. It now counts what the guard actually decided.