perf(statuspages): page the monitor list and batch the group import
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m59s
ci / test (pull_request) Successful in 12m44s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Canceled after 1m1s

With thousands of monitors on a status page the editor was tens of
megabytes, as every row carried the options of all groups, and
importing the monitor groups updated each monitor in its own statement.

- The monitors of the editor are shown 50 at a time. All rows stay in
  the form, as saving replaces the page's monitors.
- Rows carry their own group only and get the other options from the
  row template once shown or focused.
- The filter matches a monitor's name and group path only, no longer
  the names of the groups in its select.
- The import creates the groups one nesting level at a time and files
  all monitors in one statement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-26 23:38:08 +01:00
1 parent 383b63bc0e
commit 52d2ce25c9
10 files changed
+707 -340

No files matched your search

+41 -30
View File
@@ -256,7 +256,7 @@ func (s *Server) importStatusPageGroups(c *gin.Context) {
pageID := uuid.MustParse(c.Param("id"))
p := current(c)
ctx := c.Request.Context()
var created []store.StatusPageGroup
var created []pageGroupView
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
if _, err := q.GetStatusPage(ctx, pageID); err != nil {
return err
@@ -290,54 +290,66 @@ func (s *Server) importStatusPageGroups(c *gin.Context) {
if err := q.ClearStatusPageGroups(ctx, pageID); err != nil {
return err
}
mapped := map[uuid.UUID]store.StatusPageGroup{}
var createErr error
// Large organizations have thousands of monitors and hundreds of
// groups, so both are written in a few statements: the groups one
// level of nesting at a time, as parents must exist before their
// children, the monitors all at once.
mapped := map[uuid.UUID]pageGroupView{}
var levels []store.CreateStatusPageGroupsParams
posByParent := map[uuid.UUID]int32{}
tree.walk(func(g store.MonitorGroup, _ int) {
if createErr != nil || !needed[g.ID] {
tree.walk(func(g store.MonitorGroup, depth int) {
if !needed[g.ID] {
return
}
var parentKey uuid.UUID
var parentID *uuid.UUID
if g.ParentID != nil {
if parent, ok := mapped[*g.ParentID]; ok {
pid := parent.ID
parentID = &pid
parentKey = pid
}
}
var parentKey uuid.UUID
if parentID != nil {
parentKey = *parentID
}
pos := posByParent[parentKey]
posByParent[parentKey] = pos + 1
row, err := q.CreateStatusPageGroup(ctx, store.CreateStatusPageGroupParams{
PageID: pageID,
OrgID: p.Org.ID,
ParentID: parentID,
Name: g.Name,
Position: pos,
})
if err != nil {
createErr = err
return
}
row := pageGroupView{ID: uuid.New(), Name: g.Name, ParentID: parentID, Position: pos}
mapped[g.ID] = row
created = append(created, row)
for len(levels) <= depth {
levels = append(levels, store.CreateStatusPageGroupsParams{PageID: pageID, OrgID: p.Org.ID})
}
l := &levels[depth]
l.Ids = append(l.Ids, row.ID)
l.ParentIds = append(l.ParentIds, parentKey)
l.Names = append(l.Names, row.Name)
l.Positions = append(l.Positions, row.Position)
})
if createErr != nil {
return createErr
for _, l := range levels {
if len(l.Ids) == 0 {
continue
}
if err := q.CreateStatusPageGroups(ctx, l); err != nil {
return err
}
}
set := store.SetStatusPageMonitorGroupsParams{PageID: pageID}
for _, m := range listed {
var gid *uuid.UUID
var gid uuid.UUID
section := ""
if m.MonitorGroupID != nil {
if g, ok := mapped[*m.MonitorGroupID]; ok {
id := g.ID
gid = &id
gid = g.ID
section = g.Name
}
}
if err := q.SetStatusPageMonitorGroup(ctx, store.SetStatusPageMonitorGroupParams{
PageID: pageID, MonitorID: m.MonitorID, GroupID: gid, Section: section,
}); err != nil {
set.MonitorIds = append(set.MonitorIds, m.MonitorID)
set.GroupIds = append(set.GroupIds, gid)
set.Sections = append(set.Sections, section)
}
if len(set.MonitorIds) > 0 {
if err := q.SetStatusPageMonitorGroups(ctx, set); err != nil {
return err
}
}
@@ -351,11 +363,10 @@ func (s *Server) importStatusPageGroups(c *gin.Context) {
internalError(c, err)
return
}
out := make([]pageGroupView, 0, len(created))
for _, g := range created {
out = append(out, pageGroupView{ID: g.ID, Name: g.Name, ParentID: g.ParentID, Position: g.Position})
if created == nil {
created = []pageGroupView{}
}
c.JSON(http.StatusOK, gin.H{"groups": out})
c.JSON(http.StatusOK, gin.H{"groups": created})
}
// resolvePageMonitorGroup returns the status page group ID and section label