Console: each settings section reads only what it shows
bcfef0ad took the scripted session from 987 to 1055 S3 requests, over its 1000 ceiling: the new Placement section, like every section, ran populateAppSettings in full (the whole settings record, telemetry and the swap policy, 34 calls warm) though it renders none of it. settingsSectionReadsFor names what each section renders: General the record and the swap policy; Domains, Environments, Storage, Email and Feature flags the record; Errors and analytics the telemetry; Placement its registry read; Delete nothing beyond the app-tab frame. The session drops to 863. Every screen's status is unchanged; perf-budgets.txt's two settings reasons give the new counts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+85
−10
internal/console/appsettings_sections_test.go+41 −0internal/console/server.go+42 −8internal/console/testdata/perf-budgets.txt+2 −2
CI failed — run details
diff --git a/internal/console/appsettings_sections_test.go b/internal/console/appsettings_sections_test.go| index 01ee7877b..2d72bb064 100644 |
| --- a/internal/console/appsettings_sections_test.go |
| +++ b/internal/console/appsettings_sections_test.go |
| @@ -253,3 +253,44 @@ func TestBucketlessSettingsSectionsExplainConfiguration(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestSettingsSectionsReadOnlyWhatTheyShow: each section is built from only |
| +// the parts settingsSectionReadsFor names for it, so the template must |
| +// render every section with nothing else filled in. A section that starts |
| +// reading .Settings without its record fails here on the nil pointer |
| +// rather than in production; and the slim sections stay slim. |
| +func TestSettingsSectionsReadOnlyWhatTheyShow(t *testing.T) { |
| + for section := range appSettingsSections { |
| + if section == "pipeline" { |
| + continue // its own page, handlePipelineSettingsPage |
| + } |
| + reads := settingsSectionReadsFor(section) |
| + p := page{ |
| + Title: "Settings", AppName: "shop", ActiveTab: "settings", Role: RoleOwner, |
| + Account: &Account{Name: "ops", Sqid: "bab"}, Base: "/a/bab", Nav: "/a/bab", |
| + Detail: &AppView{App: "shop"}, |
| + } |
| + setAppSettingsSection(&p, section) |
| + if reads.record { |
| + p.Settings = &SettingsView{} |
| + } |
| + var buf bytes.Buffer |
| + if err := templates.ExecuteTemplate(&buf, "app_settings", p); err != nil { |
| + t.Errorf("section %s renders from %+v only: %v", section, reads, err) |
| + } |
| + } |
| + for _, section := range []string{"placement", "errors-analytics", "delete"} { |
| + if settingsSectionReadsFor(section).record { |
| + t.Errorf("section %s builds the whole settings record it never shows", section) |
| + } |
| + } |
| + if r := settingsSectionReadsFor("general"); !r.record || !r.swap || r.telemetry { |
| + t.Errorf("general reads %+v, want the record and the swap policy only", r) |
| + } |
| + if r := settingsSectionReadsFor("errors-analytics"); !r.telemetry || r.swap || r.placement { |
| + t.Errorf("errors-analytics reads %+v, want telemetry only", r) |
| + } |
| + if r := settingsSectionReadsFor("placement"); !r.placement || r.telemetry || r.swap { |
| + t.Errorf("placement reads %+v, want its registry read only", r) |
| + } |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index 3a81eaf64..282fb5317 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -4194,10 +4194,7 @@ func (s *Server) handleAppSettings(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| setAppSettingsSection(&p, section) |
| - s.populateAppSettings(r, &p, acct) |
| - if section == "placement" { |
| - s.populateAppPlacement(&p, acct) |
| - } |
| + s.populateAppSettings(r, &p, acct, section) |
| s.render(w, http.StatusOK, "app_settings", p) |
| } |
| @@ -4225,8 +4222,46 @@ func setAppSettingsSection(p *page, section string) { |
| } |
| } |
| -func (s *Server) populateAppSettings(r *http.Request, p *page, acct *Account) { |
| - p.Settings = s.assembleSettings(r.Context(), p, acct) |
| +// settingsSectionReads is what one settings section renders beyond the |
| +// app-tab frame, so a section view reads only that. record is the |
| +// SettingsView assembleSettings builds (domains, gates, environments, |
| +// storage, email, features, rename and the account move: every section that |
| +// reads .Settings); telemetry is the resolved errors and analytics settings; |
| +// swap is the swap policy; placement is the Placement section's registry |
| +// read. A section that reads none of these (Delete) costs only the frame. |
| +type settingsSectionReads struct{ record, telemetry, swap, placement bool } |
| + |
| +func settingsSectionReadsFor(section string) settingsSectionReads { |
| + switch section { |
| + case "general": |
| + return settingsSectionReads{record: true, swap: true} |
| + case "placement": |
| + return settingsSectionReads{placement: true} |
| + case "errors-analytics": |
| + return settingsSectionReads{telemetry: true} |
| + case "delete": |
| + return settingsSectionReads{} |
| + default: // domains, environments, storage, email, features |
| + return settingsSectionReads{record: true} |
| + } |
| +} |
| + |
| +// populateAppSettings fills what section shows, and only that (see |
| +// settingsSectionReadsFor). |
| +func (s *Server) populateAppSettings(r *http.Request, p *page, acct *Account, section string) { |
| + reads := settingsSectionReadsFor(section) |
| + if reads.record { |
| + p.Settings = s.assembleSettings(r.Context(), p, acct) |
| + } |
| + if reads.placement { |
| + s.populateAppPlacement(p, acct) |
| + } |
| + if reads.swap { |
| + s.loadSwapPolicy(r.Context(), p, acct) |
| + } |
| + if !reads.telemetry { |
| + return |
| + } |
| // The Errors log level this app resolves to, and where it comes from — |
| // the one setting the tab itself cannot change. A failed read is said |
| // rather than defaulted (see ErrLevelUnread), and never fails a page |
| @@ -4240,7 +4275,6 @@ func (s *Server) populateAppSettings(r *http.Request, p *page, acct *Account) { |
| // The analytics switch is the OTHER half of that same resolved object — |
| // one settings file, one read — under the name its own section uses. |
| p.AnalyticsSetting, p.AnalyticsUnread = p.ErrLevelSetting, p.ErrLevelUnread |
| - s.loadSwapPolicy(r.Context(), p, acct) |
| } |
| func (s *Server) renderAppSettingsForm(w http.ResponseWriter, r *http.Request, status int, section, msg string, drafts map[string]string) { |
| @@ -4253,7 +4287,7 @@ func (s *Server) renderAppSettingsForm(w http.ResponseWriter, r *http.Request, s |
| p.SettingsRenameTo = drafts["rename"] |
| p.SettingsDomain = drafts["domain"] |
| p.SettingsChannel = drafts["channel"] |
| - s.populateAppSettings(r, &p, acct) |
| + s.populateAppSettings(r, &p, acct, section) |
| s.render(w, status, "app_settings", p) |
| } |
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt| index d5a865490..6da4cc755 100644 |
| --- a/internal/console/testdata/perf-budgets.txt |
| +++ b/internal/console/testdata/perf-budgets.txt |
| @@ -47,8 +47,8 @@ GET /a/{sqid}/apps/{app}/instances over: the app-tab frame plus instances.json, |
| GET /a/{sqid}/apps/{app}/instances/{host} over: the app-tab frame plus the instance record, and the box reports and the fleet box reports listed and read three times (31 S3 calls warm) |
| GET /a/{sqid}/apps/{app}/logs over: the app-tab frame plus a listing and a read of every instance record and three listings for the log chunks (15 S3 calls warm) |
| GET /a/{sqid}/apps/{app}/releases over: the app-tab frame plus a second pipeline read for the pending card, the release and tag listings, at most 20 manifests, retention and instances.json (14 S3 calls warm; 12 on the fixture's empty page 2) |
| -GET /a/{sqid}/apps/{app}/settings over: populateAppSettings builds every section: each environment and its store read twice, every instance record, the domain claims, cert-warm records, every box report and a listing of every key under the app (34 S3 calls warm) |
| -GET /a/{sqid}/apps/{app}/settings/{section} over: every section is built whichever one is shown, as on the general section (34 S3 calls warm; the pipeline section 8; the advanced redirect none) |
| +GET /a/{sqid}/apps/{app}/settings over: General builds the whole settings record: each environment and its store read twice, every instance record, the domain claims, cert-warm records, every box report and a listing of every key under the app, plus the swap policy (32 S3 calls warm) |
| +GET /a/{sqid}/apps/{app}/settings/{section} over: Domains, Environments, Storage, Email and Feature flags build the whole settings record, as General does (31 S3 calls warm; General 32); Errors and analytics 9, the pipeline section 8, Placement and Delete 7 (the app-tab frame); the advanced redirect none |
| GET /a/{sqid}/fleet over: reads status/fleet.json and lists and reads each customer fleet's box reports (3 S3 calls warm) |
| GET /a/{sqid}/fleets/{fleet} over: lists and reads the fleet's box reports (2 S3 calls warm) |
| GET /a/{sqid}/settings over: reads the account and app telemetry settings and the storage entitlement (3 S3 calls warm) |