carlos / platform Public

code-health: lower the record after the console request contexts

make code-health-record after this branch's three console commits:
db-no-context in internal/console falls from 629 to 591 calls (38
sites dropped), and from 935 to 897 over the whole tree.

The banner notice that render records becomes one page field,
bannerNotice (its account, its rows and the request's context), in
place of planSeen, planAcctID and the planCtx field the gates commit
added. That keeps server.go inside its file-lines record (4,219 code
lines against 4,220) rather than raising it by one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev febbec4fc05e994d82051269511e64b74d99cb88 parent d1c427c
3 files changed, +20 −53
  • .amadan/code-health.tsv +1 −39
  • internal/console/plangracepass.go +13 −4
  • internal/console/server.go +6 −10

CI cancelled — superseded by a newer push — run details

diff --git a/.amadan/code-health.tsv b/.amadan/code-health.tsv
index 16ef2deaa..f7870e1d4 100644
--- a/.amadan/code-health.tsv
+++ b/.amadan/code-health.tsv
@@ -1342,14 +1342,11 @@ db-no-context internal/console (*Server).registeredPurchase console.sqlHandle.Qu
db-no-context internal/console (*Store).ARRSnapshots console.sqlHandle.Query 1
db-no-context internal/console (*Store).AcceptInvite console.sqlHandle.Begin 1
db-no-context internal/console (*Store).AccountAnyBySqid console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).AccountByID console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).AccountBySqid console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).AccountCLITokens console.sqlHandle.Query 1
db-no-context internal/console (*Store).AccountDays console.sqlHandle.Query 1
-db-no-context internal/console (*Store).AccountPlan console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).AccountTiers console.sqlHandle.Query 1
db-no-context internal/console (*Store).Accounts console.sqlHandle.Query 1
-db-no-context internal/console (*Store).AccountsFor console.sqlHandle.Query 1
db-no-context internal/console (*Store).AccountsPage console.sqlHandle.Query 1
db-no-context internal/console (*Store).AccountsPage console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).AddAlertConnectorVerify console.sqlHandle.Begin 1
@@ -1375,14 +1372,11 @@ db-no-context internal/console (*Store).AlertUnsubscribes console.sqlHandle.Quer
db-no-context internal/console (*Store).AppAccounts console.sqlHandle.Query 1
db-no-context internal/console (*Store).AppCount console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).AppFlags console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).AppLife console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).AppNameState console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).AppRegion console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).AppRows console.sqlHandle.Query 1
db-no-context internal/console (*Store).ApproveCLIAuth console.sqlHandle.Exec 1
db-no-context internal/console (*Store).ApproveLinkAuth console.sqlHandle.Exec 1
db-no-context internal/console (*Store).AppsFor console.sqlHandle.Query 1
-db-no-context internal/console (*Store).AppsIn console.sqlHandle.Query 1
db-no-context internal/console (*Store).AppsIncludingTrashIn console.sqlHandle.Query 1
db-no-context internal/console (*Store).AppsWithActionSince console.sqlHandle.Query 1
db-no-context internal/console (*Store).BackfillOpsMemberships (*sql.Tx).Exec 2
@@ -1407,12 +1401,6 @@ db-no-context internal/console (*Store).BillingRetiring console.sqlHandle.QueryR
db-no-context internal/console (*Store).BindClaimAppIdentity console.sqlHandle.Exec 1
db-no-context internal/console (*Store).BindClaimAppOperation console.sqlHandle.Exec 1
db-no-context internal/console (*Store).CLIAuthByUserCode console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).CLIPrincipal console.sqlHandle.Exec 1
-db-no-context internal/console (*Store).CLIPrincipal console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).CLITokenAddress console.sqlHandle.Exec 1
-db-no-context internal/console (*Store).CLITokenAddress console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).CLITokens console.sqlHandle.Query 1
-db-no-context internal/console (*Store).CapStates console.sqlHandle.Query 1
db-no-context internal/console (*Store).ClaimAppID console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).ClearLapse console.sqlHandle.Exec 1
db-no-context internal/console (*Store).ClearLaunchSponsorship console.sqlHandle.Exec 1
@@ -1421,8 +1409,6 @@ db-no-context internal/console (*Store).CloseBillingProblem console.sqlHandle.Ex
db-no-context internal/console (*Store).CloseBillingProblemsByReason console.sqlHandle.Exec 1
db-no-context internal/console (*Store).CommitAlertStep (*sql.Tx).Exec 1
db-no-context internal/console (*Store).CommitAlertStep console.sqlHandle.Begin 1
-db-no-context internal/console (*Store).CompleteGettingStarted console.sqlHandle.Exec 1
-db-no-context internal/console (*Store).CompleteGettingStarted console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).ConfirmAlertConnector console.sqlHandle.Exec 1
db-no-context internal/console (*Store).ConfirmAlertConnectorByToken (*sql.Tx).Exec 3
db-no-context internal/console (*Store).ConfirmAlertConnectorByToken (*sql.Tx).QueryRow 1
@@ -1468,7 +1454,6 @@ db-no-context internal/console (*Store).EnsureAccount (*sql.Tx).Exec 1
db-no-context internal/console (*Store).EnsureAccount console.sqlHandle.Begin 1
db-no-context internal/console (*Store).EnsureDefaultPlans console.sqlHandle.Exec 1
db-no-context internal/console (*Store).EnsureUser console.sqlHandle.Exec 1
-db-no-context internal/console (*Store).Events console.sqlHandle.Query 1
db-no-context internal/console (*Store).FinishOutbox (*sql.Tx).Exec 1
db-no-context internal/console (*Store).FinishOutbox (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).FinishOutbox console.sqlHandle.Begin 1
@@ -1478,22 +1463,17 @@ db-no-context internal/console (*Store).FirstSnapshotDay console.sqlHandle.Query
db-no-context internal/console (*Store).FlagRestoreCheck (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).FlagRestoreCheck console.sqlHandle.Begin 1
db-no-context internal/console (*Store).FreshStepUp console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).GettingStartedMarks console.sqlHandle.Query 1
db-no-context internal/console (*Store).GrantAt console.sqlHandle.Exec 1
db-no-context internal/console (*Store).GrantToken console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).HasApp console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).HasAppIn console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).HasOwners console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).HasPayment console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).HasTrashedAppIn console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).HoldConnectorOutbox console.sqlHandle.Exec 1
db-no-context internal/console (*Store).HoldEmailChallenge (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).HoldEmailChallenge console.sqlHandle.Begin 1
db-no-context internal/console (*Store).HoldMoveLog console.sqlHandle.Exec 1
db-no-context internal/console (*Store).InteractiveEndRecorded console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).IsOperator console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).LapseItems console.sqlHandle.Query 1
-db-no-context internal/console (*Store).LastAccount console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).LastIncarnation console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).LatestEURRates console.sqlHandle.Query 1
db-no-context internal/console (*Store).LatestEURRates console.sqlHandle.QueryRow 1
@@ -1517,7 +1497,6 @@ db-no-context internal/console (*Store).MarkOpApplied (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).MarkOpApplied console.sqlHandle.Begin 1
db-no-context internal/console (*Store).MarkPlanPublished console.sqlHandle.Exec 1
db-no-context internal/console (*Store).MarkRetirementRestorable console.sqlHandle.Exec 1
-db-no-context internal/console (*Store).MemberConfirms console.sqlHandle.Query 1
db-no-context internal/console (*Store).Members console.sqlHandle.Query 1
db-no-context internal/console (*Store).MembershipTransition console.sqlHandle.Begin 1
db-no-context internal/console (*Store).MoveLogDue console.sqlHandle.Query 1
@@ -1575,7 +1554,6 @@ db-no-context internal/console (*Store).ReapAccount (*sql.Tx).Exec 3
db-no-context internal/console (*Store).ReapAccount (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).ReapAccount console.sqlHandle.Begin 1
db-no-context internal/console (*Store).RecentAlertIncidents console.sqlHandle.Query 1
-db-no-context internal/console (*Store).RecordCapNotice console.sqlHandle.Exec 1
db-no-context internal/console (*Store).RecordPayment (*sql.Tx).Exec 1
db-no-context internal/console (*Store).RecordPayment (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).RecordPayment console.sqlHandle.Begin 1
@@ -1601,7 +1579,6 @@ db-no-context internal/console (*Store).RevokeLink (*sql.Tx).Exec 2
db-no-context internal/console (*Store).RevokeLink (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).RevokeLink console.sqlHandle.Begin 1
db-no-context internal/console (*Store).RevokeServicePrincipal console.sqlHandle.Exec 1
-db-no-context internal/console (*Store).Role console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).RotateLinkToken (*sql.Tx).Exec 3
db-no-context internal/console (*Store).RotateLinkToken (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).RotateLinkToken console.sqlHandle.Begin 1
@@ -1611,7 +1588,6 @@ db-no-context internal/console (*Store).SaveBillingSync console.sqlHandle.Begin
db-no-context internal/console (*Store).SealedAlertTargets console.sqlHandle.Query 1
db-no-context internal/console (*Store).SeedOperatorAlertConnectors console.sqlHandle.Begin 1
db-no-context internal/console (*Store).ServicePrincipals console.sqlHandle.Query 1
-db-no-context internal/console (*Store).SessionAddress console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).SessionInfo console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).SessionMethodID console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).SetAccountDisabled console.sqlHandle.Exec 1
@@ -1636,7 +1612,6 @@ db-no-context internal/console (*Store).SetDomainContact console.sqlHandle.Exec
db-no-context internal/console (*Store).SetGettingStartedMark (*sql.Tx).Exec 2
db-no-context internal/console (*Store).SetGettingStartedMark console.sqlHandle.Begin 1
db-no-context internal/console (*Store).SetGrantToken console.sqlHandle.Exec 1
-db-no-context internal/console (*Store).SetLastAccount console.sqlHandle.Exec 1
db-no-context internal/console (*Store).SetMigrationMarkedETag console.sqlHandle.Exec 1
db-no-context internal/console (*Store).SetMovePageAttempt console.sqlHandle.Exec 1
db-no-context internal/console (*Store).SetOperator console.sqlHandle.Exec 1
@@ -1650,7 +1625,6 @@ db-no-context internal/console (*Store).Snooze console.sqlHandle.Exec 1
db-no-context internal/console (*Store).Snoozed console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).StallRestoreCheck (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).StallRestoreCheck console.sqlHandle.Begin 1
-db-no-context internal/console (*Store).StarredLifetimes console.sqlHandle.Query 1
db-no-context internal/console (*Store).StartLaunchSponsorship (*sql.Tx).Exec 1
db-no-context internal/console (*Store).StartLaunchSponsorship (*sql.Tx).Query 1
db-no-context internal/console (*Store).StartLaunchSponsorship console.sqlHandle.Begin 1
@@ -1665,20 +1639,15 @@ db-no-context internal/console (*Store).TakeEmailLink (*sql.Tx).Exec 1
db-no-context internal/console (*Store).TakeEmailLink (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).TakeEmailLink console.sqlHandle.Begin 1
db-no-context internal/console (*Store).TemporaryAppRows console.sqlHandle.Query 1
-db-no-context internal/console (*Store).TouchLastSeen console.sqlHandle.Exec 1
db-no-context internal/console (*Store).TransferOwnership (*sql.Tx).Exec 2
db-no-context internal/console (*Store).TransferOwnership (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).TransferOwnership console.sqlHandle.Begin 1
-db-no-context internal/console (*Store).TrashedAppsIn console.sqlHandle.Query 1
db-no-context internal/console (*Store).UnsubscribeAlertConnector (*sql.Tx).Exec 3
db-no-context internal/console (*Store).UnsubscribeAlertConnector (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).UnsubscribeAlertConnector console.sqlHandle.Begin 1
db-no-context internal/console (*Store).UseAlertToken console.sqlHandle.Begin 1
db-no-context internal/console (*Store).allocationsOrdered console.sqlHandle.Query 1
db-no-context internal/console (*Store).appIdentity console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).appLinkID console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).appLives console.sqlHandle.Query 1
-db-no-context internal/console (*Store).appPlacementRow console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).backfillAppLifetimes (*sql.Tx).Exec 1
db-no-context internal/console (*Store).backfillAppLifetimes (*sql.Tx).Query 1
db-no-context internal/console (*Store).backfillAppLifetimes console.sqlHandle.Begin 1
@@ -1708,8 +1677,6 @@ db-no-context internal/console (*Store).claimRawNewAppToken console.sqlHandle.Ex
db-no-context internal/console (*Store).claimRawNewServicePrincipalScoped (*sql.Tx).Exec 1
db-no-context internal/console (*Store).claimRawNewServicePrincipalScoped (*sql.Tx).QueryRow 1
db-no-context internal/console (*Store).claimRawNewServicePrincipalScoped console.sqlHandle.Begin 1
-db-no-context internal/console (*Store).claimRawPendingChangesFor (*sql.Tx).Query 1
-db-no-context internal/console (*Store).claimRawPendingChangesFor console.sqlHandle.Begin 1
db-no-context internal/console (*Store).claimRawProposeChange (*sql.Tx).Exec 2
db-no-context internal/console (*Store).claimRawProposeChange console.sqlHandle.Begin 1
db-no-context internal/console (*Store).claimRawPutLapseItem console.sqlHandle.Exec 1
@@ -1730,11 +1697,7 @@ db-no-context internal/console (*Store).ed25519Key console.sqlHandle.Exec 1
db-no-context internal/console (*Store).ed25519Key console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).eurRatesFetchedAt console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).feed console.sqlHandle.Query 1
-db-no-context internal/console (*Store).hasClaimedSource console.sqlHandle.QueryRow 1
db-no-context internal/console (*Store).insertEmailChallenge (*sql.Tx).Exec 1
-db-no-context internal/console (*Store).linkPrincipalLive console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).linkRow console.sqlHandle.QueryRow 1
-db-no-context internal/console (*Store).linkedAppHomes console.sqlHandle.Query 1
db-no-context internal/console (*Store).linksNeedingSync console.sqlHandle.Query 1
db-no-context internal/console (*Store).markLinkSynced console.sqlHandle.Exec 1
db-no-context internal/console (*Store).migrate console.sqlHandle.Exec 2
@@ -1808,7 +1771,6 @@ db-no-context internal/console billingSetPlan (*sql.Tx).QueryRow 1
db-no-context internal/console bumpDoorKeyRevision (*sql.Tx).Exec 1
db-no-context internal/console bumpDoorKeyRevision (*sql.Tx).QueryRow 1
db-no-context internal/console claimSQLCensus (*sql.DB).Query 4
-db-no-context internal/console confirmsFor (*sql.Tx).Query 1
db-no-context internal/console consumeSeatAuthorisationTx (*sql.Tx).Exec 1
db-no-context internal/console deleteAlertConnectorTx (*sql.Tx).Exec 3
db-no-context internal/console deleteBound (*sql.Tx).Exec 1
@@ -2253,7 +2215,7 @@ file-lines . apimode.go - 4199
file-lines . apimode_test.go - 3530 # raised: fdc912b (batch 2, #1123) landed before the ratchet; tests for the system update refusals
file-lines internal/activator activator.go - 3778
file-lines internal/activator activator_test.go - 5499
-file-lines internal/console server.go - 4220
+file-lines internal/console server.go - 4219
file-lines internal/host agent.go - 3214
file-lines internal/provision reconcile_test.go - 3094
file-lines internal/registry registry_test.go - 3261
diff --git a/internal/console/plangracepass.go b/internal/console/plangracepass.go
index 01497eebf..0b272cda9 100644
--- a/internal/console/plangracepass.go
+++ b/internal/console/plangracepass.go
@@ -393,14 +393,23 @@ func shownStates(states []capState, now time.Time) []capState {
return out
}
+// bannerNotice is a page's plan banner as an owner was shown it: the
+// account, the over rows behind it (planBanner's second answer) and the
+// request it was served on, whose context the notice write runs under.
+type bannerNotice struct {
+ ctx context.Context
+ accountID int64
+ seen []capState
+}
+
// recordBannerNotice records notice for a page whose banner was served to
// an owner, under that page's request context.
-func (s *Server) recordBannerNotice(ctx context.Context, accountID int64, seen []capState, now time.Time) {
- if len(seen) == 0 {
+func (s *Server) recordBannerNotice(n bannerNotice, now time.Time) {
+ if len(n.seen) == 0 {
return
}
- if err := s.store.RecordCapNotice(ctx, accountID, seen, now); err != nil {
- log.Printf("console: plan banner %d: notice: %v", accountID, err)
+ if err := s.store.RecordCapNotice(n.ctx, n.accountID, n.seen, now); err != nil {
+ log.Printf("console: plan banner %d: notice: %v", n.accountID, err)
}
}
diff --git a/internal/console/server.go b/internal/console/server.go
index 546ac6b9b..2e7e5b828 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -2446,13 +2446,9 @@ type page struct {
BillingPickQuery string
// BillingNav shows the account nav's billing link: billing is on.
BillingNav bool
- // planSeen are the over rows behind PlanNotices when the viewer owns
- // the account; render records them as notice once the page is written,
- // under planCtx, the request's context, which accountPage sets with
- // them.
- planSeen []capState
- planAcctID int64
- planCtx context.Context
+ // planNotice is the over rows behind PlanNotices when the viewer owns
+ // the account; render records them as notice once the page is written.
+ planNotice bannerNotice
FlashErr string // one-shot error notice
Apps []appRow // account home
@@ -2907,7 +2903,7 @@ func (s *Server) render(w http.ResponseWriter, status int, name string, p page)
if s.writeTemplate(w, status, name, p) != nil {
return
}
- s.recordBannerNotice(p.planCtx, p.planAcctID, p.planSeen, time.Now()) // plans 4a: the banner was served
+ s.recordBannerNotice(p.planNotice, time.Now()) // plans 4a: the banner was served
}
// templateBufs holds the buffers writeTemplate renders into. One grown past
@@ -4264,8 +4260,8 @@ func (s *Server) accountPage(w http.ResponseWriter, r *http.Request, addr, raw s
p.Accounts[i].Seg = preferredSeg(p.Accounts, &p.Accounts[i])
}
p.Nav = "/a/" + url.PathEscape(preferredSeg(p.Accounts, acct))
- p.PlanNotices, p.planSeen = s.planBanner(r.Context(), acct, role, time.Now())
- p.planAcctID, p.planCtx = acct.ID, r.Context()
+ p.PlanNotices, p.planNotice.seen = s.planBanner(r.Context(), acct, role, time.Now())
+ p.planNotice.ctx, p.planNotice.accountID = r.Context(), acct.ID
if role == RoleOwner && s.planKeepOffered(r.Context(), acct) {
p.PlanKeepURL = "/a/" + url.PathEscape(acct.Sqid) + "/plan/keep"
p.PlanKeepLink = planKeepCopy["keep.link"]