PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FEATURE (backups): Collapse consecutive WAL segments into range rows and page backup lists by cursor, so backups past the first 1000 rows stay reachable
Rostislav Dugin062f7f3492bd
diff --git a/backend/internal/features/backups/backups/controllers/physical/controller.go b/backend/internal/features/backups/backups/controllers/physical/controller.goindex 4d65e98b..613837cf 100644--- a/backend/internal/features/backups/backups/controllers/physical/controller.go+++ b/backend/internal/features/backups/backups/controllers/physical/controller.go@@ -55,13 +55,13 @@ func (c *PhysicalBackupController) GetRecoveryScript(ctx *gin.Context) {// GetBackups// @Summary List physical backups for a database-// @Description Returns a page of physical backups — FULLs, incrementals and committed WAL segments — as one flat list newest-first, with the database's total on-disk usage and the total count for pagination. The frontend filters by type.+// @Description Returns a page of physical backups — FULLs, incrementals and WAL ranges of consecutive committed segments — as one flat list newest-first, with the database's total on-disk usage. nextCursor is set while further rows exist; pass it as cursor to get the next page. A malformed cursor returns 400.// @Tags backups-physical// @Produce json// @Security BearerAuth// @Param id path string true "Database ID"// @Param limit query int false "Page size (default 50, max 1000)"-// @Param offset query int false "Offset for pagination" default(0)+// @Param cursor query string false "nextCursor of the previous page; omit for the first page"// @Param type query []string false "Filter by backup type - repeatable, matches any" Enums(FULL, INCREMENTAL, WAL) collectionFormat(multi)// @Param status query []string false "Filter by status - repeatable, matches any (e.g. COMPLETED, IN_PROGRESS)" collectionFormat(multi)// @Param beforeDate query string false "Keep only backups created before this date (RFC3339)" format(date-time)diff --git a/backend/internal/features/backups/backups/controllers/physical/controller_test.go b/backend/internal/features/backups/backups/controllers/physical/controller_test.goindex a3c4b54d..0a297143 100644--- a/backend/internal/features/backups/backups/controllers/physical/controller_test.go+++ b/backend/internal/features/backups/backups/controllers/physical/controller_test.go@@ -39,6 +39,7 @@ import (workspaces_controllers "databasus-backend/internal/features/workspaces/controllers"workspaces_models "databasus-backend/internal/features/workspaces/models"workspaces_testing "databasus-backend/internal/features/workspaces/testing"+ "databasus-backend/internal/storage""databasus-backend/internal/util/encryption""databasus-backend/internal/util/logger"test_utils "databasus-backend/internal/util/testing"@@ -139,7 +140,6 @@ func Test_GetBackups_WhenOwner_ReturnsFlatListSortedByCreatedAt(t *testing.T) {"Bearer "+prereqs.user.Token, http.StatusOK, &response)require.Len(t, response.Backups, 3)- assert.EqualValues(t, 3, response.Total)// Newest-first: WAL (received last), then incremental, then full.assert.Equal(t, walSegment.ID, response.Backups[0].ID)@@ -150,7 +150,8 @@ func Test_GetBackups_WhenOwner_ReturnsFlatListSortedByCreatedAt(t *testing.T) {assert.Equal(t, physical_enums.PhysicalBackupTypeFull, response.Backups[2].Type)assert.Equal(t, full.ID, *response.Backups[1].RootFullBackupID)- assert.NotNil(t, response.Backups[0].WalFilename)+ require.NotNil(t, response.Backups[0].FromWalFilename)+ assert.Equal(t, "000000010000000000000002", *response.Backups[0].FromWalFilename)assert.Positive(t, response.TotalUsageMb)}@@ -190,48 +191,93 @@ func Test_GetBackups_WhenBackupFailed_ReturnsFailMessage(t *testing.T) {"a completed backup carries no failure message")}-func Test_GetBackups_Paginated_ReturnsRequestedPage(t *testing.T) {+func Test_GetBackups_FollowingNextCursor_ReturnsEveryRowOnce(t *testing.T) {prereqs := createPhysicalControllerPrereqs(t)- base := time.Now().UTC().Add(-1 * time.Hour)+ fulls := createFullBackupsMinutesApart(t, prereqs, 5, time.Now().UTC().Add(-1*time.Hour))- fullModel := physical_testing.NewTestCompletedFullBackup(- prereqs.database.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes))- fullModel.CreatedAt = base- full := physical_testing.CreateTestFullBackup(t, fullModel)+ firstPage := getBackups(t, prereqs, "?limit=2")+ require.Len(t, firstPage.Backups, 2)+ require.NotEmpty(t, firstPage.NextCursor)- incrModel := physical_testing.NewTestCompletedIncrementalBackup(- prereqs.database.ID, prereqs.storage.ID, full.ID, nil, 1,- walmath.LSN(segmentBytes), walmath.LSN(2*segmentBytes))- incrModel.CreatedAt = base.Add(10 * time.Minute)- incr := physical_testing.CreateTestIncrementalBackup(t, incrModel)+ secondPage := getBackups(t, prereqs, "?limit=2&cursor="+firstPage.NextCursor)+ require.Len(t, secondPage.Backups, 2)+ require.NotEmpty(t, secondPage.NextCursor)- walModel := physical_testing.NewTestWalSegment(- prereqs.database.ID, prereqs.storage.ID, 1, "000000010000000000000002",- walmath.LSN(2*segmentBytes), walmath.LSN(3*segmentBytes))- walModel.ReceivedAt = base.Add(20 * time.Minute)- walSegment := physical_testing.CreateTestWalSegment(t, walModel)+ lastPage := getBackups(t, prereqs, "?limit=2&cursor="+secondPage.NextCursor)+ require.Len(t, lastPage.Backups, 1)+ assert.Empty(t, lastPage.NextCursor, "the page holding the oldest row carries no cursor")++ listedIDs := collectBackupIDs(firstPage, secondPage, lastPage)+ assert.Equal(t, []uuid.UUID{fulls[4].ID, fulls[3].ID, fulls[2].ID, fulls[1].ID, fulls[0].ID}, listedIDs)+}++func Test_GetBackups_WhenBackupCreatedBetweenPages_NoRowRepeatedOrSkipped(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ fulls := createFullBackupsMinutesApart(t, prereqs, 3, time.Now().UTC().Add(-1*time.Hour))++ firstPage := getBackups(t, prereqs, "?limit=2")+ require.NotEmpty(t, firstPage.NextCursor)++ physical_testing.CreateTestFullBackup(t, physical_testing.NewTestCompletedFullBackup(+ prereqs.database.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes)))++ secondPage := getBackups(t, prereqs, "?limit=2&cursor="+firstPage.NextCursor)++ listedIDs := collectBackupIDs(firstPage, secondPage)+ assert.Equal(t, []uuid.UUID{fulls[2].ID, fulls[1].ID, fulls[0].ID}, listedIDs)+}++func Test_GetBackups_WhenCursorMalformed_Returns400(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)listURL := "/api/v1/backups/physical/database/" + prereqs.database.ID.String() + "/backups"- var firstPage backups_dto_physical.GetPhysicalBackupsResponse- test_utils.MakeGetRequestAndUnmarshal(t, prereqs.router,- listURL+"?limit=2&offset=0", "Bearer "+prereqs.user.Token, http.StatusOK, &firstPage)+ for _, malformedCursor := range []string{"not-a-cursor", "e30", "eyJ0IjoieCJ9"} {+ test_utils.MakeGetRequest(t, prereqs.router,+ listURL+"?cursor="+malformedCursor, "Bearer "+prereqs.user.Token, http.StatusBadRequest)+ }+}- require.Len(t, firstPage.Backups, 2)- assert.EqualValues(t, 3, firstPage.Total)- assert.Equal(t, 2, firstPage.Limit)- assert.Equal(t, 0, firstPage.Offset)- assert.Equal(t, walSegment.ID, firstPage.Backups[0].ID)- assert.Equal(t, incr.ID, firstPage.Backups[1].ID)+func Test_GetBackups_WithCursorFromAnotherDatabase_ReturnsOnlyRequestedDatabaseRows(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)- var secondPage backups_dto_physical.GetPhysicalBackupsResponse+ base := time.Now().UTC().Add(-1 * time.Hour)+ ownFulls := createFullBackupsMinutesApart(t, prereqs, 2, base)++ other := createSecondPhysicalDatabase(t, prereqs)+ for index := range 2 {+ otherModel := physical_testing.NewTestCompletedFullBackup(+ other.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes))+ otherModel.CreatedAt = base.Add(time.Duration(30+index) * time.Minute)+ physical_testing.CreateTestFullBackup(t, otherModel)+ }++ var otherPage backups_dto_physical.GetPhysicalBackupsResponsetest_utils.MakeGetRequestAndUnmarshal(t, prereqs.router,- listURL+"?limit=2&offset=2", "Bearer "+prereqs.user.Token, http.StatusOK, &secondPage)+ "/api/v1/backups/physical/database/"+other.ID.String()+"/backups?limit=1",+ "Bearer "+prereqs.user.Token, http.StatusOK, &otherPage)+ require.NotEmpty(t, otherPage.NextCursor)++ page := getBackups(t, prereqs, "?cursor="+otherPage.NextCursor)++ assert.Equal(t, []uuid.UUID{ownFulls[1].ID, ownFulls[0].ID}, collectBackupIDs(page))+}++func Test_GetBackups_WithCursor_WhenNonMember_ReturnsError(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ createFullBackupsMinutesApart(t, prereqs, 2, time.Now().UTC().Add(-1*time.Hour))++ firstPage := getBackups(t, prereqs, "?limit=1")+ require.NotEmpty(t, firstPage.NextCursor)- require.Len(t, secondPage.Backups, 1)- assert.EqualValues(t, 3, secondPage.Total)- assert.Equal(t, full.ID, secondPage.Backups[0].ID)+ outsider := users_testing.CreateTestUser(t.Context(), users_enums.UserRoleMember)++ test_utils.MakeGetRequest(t, prereqs.router,+ "/api/v1/backups/physical/database/"+prereqs.database.ID.String()+"/backups?cursor="+firstPage.NextCursor,+ "Bearer "+outsider.Token, http.StatusBadRequest)}func Test_GetBackups_WhenNonMember_ReturnsError(t *testing.T) {@@ -721,7 +767,6 @@ func Test_GetBackups_FilterByType_ReturnsOnlyThatType(t *testing.T) {fullPage := getBackups(t, prereqs, "?type=FULL")require.Len(t, fullPage.Backups, 1)assert.Equal(t, full.ID, fullPage.Backups[0].ID)- assert.EqualValues(t, 1, fullPage.Total)incrPage := getBackups(t, prereqs, "?type=INCREMENTAL")require.Len(t, incrPage.Backups, 1)@@ -769,7 +814,6 @@ func Test_GetBackups_FilterByBeforeDate_ExcludesNewer(t *testing.T) {require.Len(t, page.Backups, 1)assert.Equal(t, older.ID, page.Backups[0].ID)- assert.EqualValues(t, 1, page.Total)}func Test_GetBackups_FilterByMultipleTypes_ReturnsThoseTypes(t *testing.T) {@@ -780,7 +824,6 @@ func Test_GetBackups_FilterByMultipleTypes_ReturnsThoseTypes(t *testing.T) {page := getBackups(t, prereqs, "?type=FULL&type=WAL")require.Len(t, page.Backups, 2)- assert.EqualValues(t, 2, page.Total)returnedIDs := []uuid.UUID{page.Backups[0].ID, page.Backups[1].ID}assert.Contains(t, returnedIDs, full.ID)@@ -803,7 +846,6 @@ func Test_GetBackups_FilterByMultipleStatuses_ReturnsThoseStatuses(t *testing.T)page := getBackups(t, prereqs, "?status=COMPLETED&status=IN_PROGRESS")require.Len(t, page.Backups, 2)- assert.EqualValues(t, 2, page.Total)returnedIDs := []uuid.UUID{page.Backups[0].ID, page.Backups[1].ID}assert.Contains(t, returnedIDs, completed.ID)@@ -829,7 +871,6 @@ func Test_GetBackups_FilterByTypesAndStatuses_AppliesAndAcrossDimensions(t *testrequire.Len(t, page.Backups, 1)assert.Equal(t, completedFull.ID, page.Backups[0].ID)- assert.EqualValues(t, 1, page.Total)}// --- List edges --------------------------------------------------------------@@ -840,7 +881,7 @@ func Test_GetBackups_WhenEmpty_ReturnsEmptyPage(t *testing.T) {page := getBackups(t, prereqs, "")assert.Empty(t, page.Backups)- assert.EqualValues(t, 0, page.Total)+ assert.Empty(t, page.NextCursor)assert.Zero(t, page.TotalUsageMb)}@@ -863,24 +904,187 @@ func Test_GetBackups_IsolatesByDatabase(t *testing.T) {func Test_GetBackups_DefaultsAndCapsPageLimit(t *testing.T) {prereqs := createPhysicalControllerPrereqs(t)+ createCompletedFullBackupsInBulk(t, prereqs, 1001)+unset := getBackups(t, prereqs, "")- assert.Equal(t, 50, unset.Limit)+ assert.Len(t, unset.Backups, 50)+ assert.NotEmpty(t, unset.NextCursor)capped := getBackups(t, prereqs, "?limit=5000")- assert.Equal(t, 1000, capped.Limit)+ assert.Len(t, capped.Backups, 1000)+ assert.NotEmpty(t, capped.NextCursor)}-func Test_GetBackups_OffsetPastEnd_ReturnsEmptyPageWithTotal(t *testing.T) {+// --- WAL ranges --------------------------------------------------------------++func Test_GetBackups_WithContiguousWalSegments_ReturnsOneRangeRow(t *testing.T) {prereqs := createPhysicalControllerPrereqs(t)- physical_testing.CreateTestFullBackup(t, physical_testing.NewTestCompletedFullBackup(- prereqs.database.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes)))+ base := time.Now().UTC().Add(-1 * time.Hour)++ fullModel := physical_testing.NewTestCompletedFullBackup(+ prereqs.database.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes))+ fullModel.CreatedAt = base+ full := physical_testing.CreateTestFullBackup(t, fullModel)- page := getBackups(t, prereqs, "?offset=10")+ segments := createContiguousWalSegments(t, prereqs, 1, 1, 5, base.Add(time.Minute))- assert.Empty(t, page.Backups)- assert.EqualValues(t, 1, page.Total)- assert.Equal(t, 10, page.Offset)+ page := getBackups(t, prereqs, "")+ require.Len(t, page.Backups, 2)++ walRange := page.Backups[0]+ assert.Equal(t, physical_enums.PhysicalBackupTypeWal, walRange.Type)+ assert.Equal(t, segments[0].ID, walRange.ID)+ assert.Equal(t, segments[0].WalFilename, *walRange.FromWalFilename)+ assert.Equal(t, segments[4].WalFilename, *walRange.ToWalFilename)+ assert.Equal(t, 5, *walRange.WalSegmentsCount)+ assert.InDelta(t, 80, walRange.SizeMb, 0.001)+ assert.Equal(t, segments[0].StartLSN.String(), walRange.StartLSN)+ assert.Equal(t, segments[4].EndLSN.String(), walRange.StopLSN)+ assert.WithinDuration(t, segments[0].ReceivedAt, walRange.CreatedAt, time.Millisecond)+ require.NotNil(t, walRange.CompletedAt)+ assert.WithinDuration(t, segments[4].ReceivedAt, *walRange.CompletedAt, time.Millisecond)+ assert.False(t, walRange.HasGapBefore)++ assert.Equal(t, full.ID, page.Backups[1].ID)+}++func Test_GetBackups_WhenWalSegmentMissing_SplitsRangeAndMarksGap(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ base := time.Now().UTC().Add(-1 * time.Hour)+ olderSegments := createContiguousWalSegments(t, prereqs, 1, 1, 2, base)+ newerSegments := createContiguousWalSegments(t, prereqs, 1, 4, 2, base.Add(10*time.Minute))++ page := getBackups(t, prereqs, "")+ require.Len(t, page.Backups, 2)++ assert.Equal(t, newerSegments[0].ID, page.Backups[0].ID)+ assert.True(t, page.Backups[0].HasGapBefore, "the range after the missing segment is marked")++ assert.Equal(t, olderSegments[0].ID, page.Backups[1].ID)+ assert.False(t, page.Backups[1].HasGapBefore, "the oldest retained range has nothing before it")+}++func Test_GetBackups_WhenTimelineSwitches_StartsNewRangeWithoutGapMark(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ base := time.Now().UTC().Add(-1 * time.Hour)+ oldTimelineSegments := createContiguousWalSegments(t, prereqs, 1, 1, 2, base)+ newTimelineSegments := createContiguousWalSegments(t, prereqs, 2, 3, 2, base.Add(10*time.Minute))++ page := getBackups(t, prereqs, "")+ require.Len(t, page.Backups, 2)++ assert.Equal(t, newTimelineSegments[0].ID, page.Backups[0].ID)+ assert.Equal(t, 2, page.Backups[0].TimelineID)+ assert.False(t, page.Backups[0].HasGapBefore, "the first range on a timeline is not a gap")++ assert.Equal(t, oldTimelineSegments[0].ID, page.Backups[1].ID)+ assert.Equal(t, 1, page.Backups[1].TimelineID)+}++func Test_GetBackups_WhenFullBetweenSegments_SplitsRangeAroundFull(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ olderSegments, full, newerSegments := seedWalAroundFull(t, prereqs)++ page := getBackups(t, prereqs, "")+ require.Len(t, page.Backups, 3)++ assert.Equal(t, newerSegments[0].ID, page.Backups[0].ID)+ assert.Equal(t, 2, *page.Backups[0].WalSegmentsCount)+ assert.False(t, page.Backups[0].HasGapBefore)++ assert.Equal(t, full.ID, page.Backups[1].ID)++ assert.Equal(t, olderSegments[0].ID, page.Backups[2].ID)+ assert.Equal(t, 2, *page.Backups[2].WalSegmentsCount)+}++func Test_GetBackups_WhenFilteredToWal_MergesRangeAcrossFull(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ olderSegments, _, newerSegments := seedWalAroundFull(t, prereqs)++ page := getBackups(t, prereqs, "?type=WAL")+ require.Len(t, page.Backups, 1)++ assert.Equal(t, olderSegments[0].ID, page.Backups[0].ID)+ assert.Equal(t, 4, *page.Backups[0].WalSegmentsCount)+ assert.Equal(t, newerSegments[1].WalFilename, *page.Backups[0].ToWalFilename)+}++func Test_GetBackups_WithBeforeDateInsideRange_RangeCoversOlderSegmentsOnly(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ base := time.Now().UTC().Add(-1 * time.Hour)+ segments := createContiguousWalSegments(t, prereqs, 1, 1, 4, base)++ cutoff := segments[1].ReceivedAt.Add(30 * time.Second).Format(time.RFC3339Nano)+ page := getBackups(t, prereqs, "?beforeDate="+cutoff)+ require.Len(t, page.Backups, 1)++ assert.Equal(t, 2, *page.Backups[0].WalSegmentsCount)+ assert.Equal(t, segments[1].WalFilename, *page.Backups[0].ToWalFilename)+ assert.InDelta(t, 32, page.Backups[0].SizeMb, 0.001)+}++func Test_GetBackups_WithStatusThatWalNeverHas_ReturnsNoWalRows(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ base := time.Now().UTC().Add(-1 * time.Hour)+ createContiguousWalSegments(t, prereqs, 1, 1, 2, base)++ failedModel := physical_testing.NewTestCompletedFullBackup(+ prereqs.database.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes))+ failedModel.Status = physical_enums.PhysicalBackupStatusError+ failed := physical_testing.CreateTestFullBackup(t, failedModel)++ page := getBackups(t, prereqs, "?status=ERROR")++ assert.Equal(t, []uuid.UUID{failed.ID}, collectBackupIDs(page))+}++func Test_GetBackups_WhenSegmentAppendedToNewestRange_RangeGrowsInPlace(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ base := time.Now().UTC().Add(-1 * time.Hour)+ segments := createContiguousWalSegments(t, prereqs, 1, 1, 2, base)++ pageBefore := getBackups(t, prereqs, "")+ require.Len(t, pageBefore.Backups, 1)++ appendedSegment := createContiguousWalSegments(t, prereqs, 1, 3, 1, base.Add(5*time.Minute))[0]++ pageAfter := getBackups(t, prereqs, "")+ require.Len(t, pageAfter.Backups, 1)++ grownRange := pageAfter.Backups[0]+ assert.Equal(t, segments[0].ID, grownRange.ID)+ assert.Equal(t, 3, *grownRange.WalSegmentsCount)+ assert.Equal(t, appendedSegment.WalFilename, *grownRange.ToWalFilename)+ assert.Greater(t, grownRange.SizeMb, pageBefore.Backups[0].SizeMb)+ assert.WithinDuration(t, appendedSegment.ReceivedAt, *grownRange.CompletedAt, time.Millisecond)+}++func Test_GetBackups_WithManyWalSegments_RangeCountsAsOneRow(t *testing.T) {+ prereqs := createPhysicalControllerPrereqs(t)++ base := time.Now().UTC().Add(-2 * time.Hour)++ fullModel := physical_testing.NewTestCompletedFullBackup(+ prereqs.database.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes))+ fullModel.CreatedAt = base+ full := physical_testing.CreateTestFullBackup(t, fullModel)++ segments := createContiguousWalSegments(t, prereqs, 1, 1, 60, base.Add(time.Minute))++ page := getBackups(t, prereqs, "?limit=2")++ assert.Equal(t, []uuid.UUID{segments[0].ID, full.ID}, collectBackupIDs(page))+ assert.Equal(t, 60, *page.Backups[0].WalSegmentsCount)+ assert.Empty(t, page.NextCursor)}// --- Cancel / delete edge cases ---------------------------------------------@@ -1177,6 +1381,108 @@ func seedOneOfEachType(t *testing.T, prereqs *physicalControllerPrereqs) (return full, incr, walSegment}+func collectBackupIDs(pages ...backups_dto_physical.GetPhysicalBackupsResponse) []uuid.UUID {+ var backupIDs []uuid.UUID++ for _, page := range pages {+ for _, backup := range page.Backups {+ backupIDs = append(backupIDs, backup.ID)+ }+ }++ return backupIDs+}++// createFullBackupsMinutesApart returns the created FULLs oldest first.+func createFullBackupsMinutesApart(+ t *testing.T,+ prereqs *physicalControllerPrereqs,+ count int,+ firstCreatedAt time.Time,+) []*physical_models.PhysicalFullBackup {+ t.Helper()++ fulls := make([]*physical_models.PhysicalFullBackup, 0, count)++ for index := range count {+ fullModel := physical_testing.NewTestCompletedFullBackup(+ prereqs.database.ID, prereqs.storage.ID, 1, walmath.LSN(0), walmath.LSN(segmentBytes))+ fullModel.CreatedAt = firstCreatedAt.Add(time.Duration(index) * time.Minute)+ fulls = append(fulls, physical_testing.CreateTestFullBackup(t, fullModel))+ }++ return fulls+}++// createCompletedFullBackupsInBulk inserts count FULL rows a second apart in+// one statement: saving them one by one through the repository takes tens of+// seconds at the page-limit cap.+func createCompletedFullBackupsInBulk(t *testing.T, prereqs *physicalControllerPrereqs, count int) {+ t.Helper()++ err := storage.GetDb().Exec(`+ INSERT INTO physical_full_backups+ (database_id, storage_id, timeline_id, status, start_lsn, stop_lsn, created_at, completed_at)+ SELECT ?, ?, 1, ?, '0/0'::pg_lsn, '0/100'::pg_lsn,+ NOW() - make_interval(secs => series_index), NOW() - make_interval(secs => series_index)+ FROM generate_series(1, ?) AS series_index`,+ prereqs.database.ID, prereqs.storage.ID, physical_enums.PhysicalBackupStatusCompleted, count,+ ).Error+ require.NoError(t, err)+}++// createContiguousWalSegments commits count segments that follow each other+// without a gap, received a minute apart, and returns them in LSN order.+func createContiguousWalSegments(+ t *testing.T,+ prereqs *physicalControllerPrereqs,+ timelineID int,+ firstSegmentNo uint64,+ count int,+ firstReceivedAt time.Time,+) []*physical_models.PhysicalWalSegment {+ t.Helper()++ segments := make([]*physical_models.PhysicalWalSegment, 0, count)++ for index := range count {+ segmentNo := walmath.WalSegmentNo(firstSegmentNo + uint64(index))++ segmentModel := physical_testing.NewTestWalSegment(+ prereqs.database.ID, prereqs.storage.ID, timelineID,+ segmentNo.GetFilename(uint32(timelineID)), segmentNo.FirstLSN(), segmentNo.Next().FirstLSN())+ segmentModel.ReceivedAt = firstReceivedAt.Add(time.Duration(index) * time.Minute)++ segments = append(segments, physical_testing.CreateTestWalSegment(t, segmentModel))+ }++ return segments+}++// seedWalAroundFull commits four contiguous segments with a FULL created after+// the second one, so only the FULL separates the two halves in the list.+func seedWalAroundFull(t *testing.T, prereqs *physicalControllerPrereqs) (+ []*physical_models.PhysicalWalSegment,+ *physical_models.PhysicalFullBackup,+ []*physical_models.PhysicalWalSegment,+) {+ t.Helper()++ base := time.Now().UTC().Add(-1 * time.Hour)+ olderSegments := createContiguousWalSegments(t, prereqs, 1, 1, 2, base)++ fullModel := physical_testing.NewTestCompletedFullBackup(+ prereqs.database.ID, prereqs.storage.ID, 1,+ walmath.WalSegmentNo(3).FirstLSN()+physical_testing.FirstRecordOffset,+ walmath.WalSegmentNo(3).FirstLSN()+physical_testing.FirstRecordOffset+physical_testing.FullLSNSpan)+ fullModel.CreatedAt = base.Add(5 * time.Minute)+ full := physical_testing.CreateTestFullBackup(t, fullModel)++ newerSegments := createContiguousWalSegments(t, prereqs, 1, 3, 2, base.Add(10*time.Minute))++ return olderSegments, full, newerSegments+}+func createSecondPhysicalDatabase(t *testing.T, prereqs *physicalControllerPrereqs) *databases.Database {t.Helper()diff --git a/backend/internal/features/backups/backups/core/physical/service/dto.go b/backend/internal/features/backups/backups/core/physical/service/dto.goindex 847a5a53..a3472060 100644--- a/backend/internal/features/backups/backups/core/physical/service/dto.go+++ b/backend/internal/features/backups/backups/core/physical/service/dto.go@@ -16,10 +16,13 @@ type DeleteOrphanWalSegmentsSpec struct {WalByteBudgetMB float64}-// PhysicalBackupListRow is one row of the merged, paginated backup list across-// the FULL, incremental and committed-WAL tables. Type-only columns are NULL for-// the other types (scanned into the pointer fields); LSNs arrive as text. It is-// the catalog-level shape the API maps to its presentation DTO.+// PhysicalBackupListRow is one row of the merged, paginated backup list: a FULL,+// an incremental, or a WAL range that collapses consecutive committed segments.+// Type-only columns are NULL for the other types (scanned into the pointer+// fields); LSNs arrive as text. A WAL range takes the ID of its lowest-LSN+// segment, so its identity survives growth at the newest end. SortTime is the+// row's position in the newest-first list: created_at for a backup, the newest+// receive time for a WAL range.type PhysicalBackupListRow struct {ID uuid.UUID `gorm:"column:id"`Type string `gorm:"column:type"`@@ -29,17 +32,29 @@ type PhysicalBackupListRow struct {StopLSN string `gorm:"column:stop_lsn"`RootFullBackupID *uuid.UUID `gorm:"column:root_full_backup_id"`ParentIncrementalBackupID *uuid.UUID `gorm:"column:parent_incremental_backup_id"`- WalFilename *string `gorm:"column:wal_filename"`+ FromWalFilename *string `gorm:"column:from_wal_filename"`+ ToWalFilename *string `gorm:"column:to_wal_filename"`+ WalSegmentsCount *int `gorm:"column:wal_segments_count"`+ HasGapBefore bool `gorm:"column:has_gap_before"`SizeMb float64 `gorm:"column:size_mb"`FailMessage *string `gorm:"column:fail_message"`CreatedAt time.Time `gorm:"column:created_at"`CompletedAt *time.Time `gorm:"column:completed_at"`+ SortTime time.Time `gorm:"column:sort_time"`}-// BackupListFilter narrows ListBackups / CountBackups. An empty slice (or nil-// BeforeDate) is "no filter on that dimension". Types and Statuses match the-// synthetic columns the UNION projects ('WAL'/'COMPLETED' for WAL rows) and-// match any of their values; BeforeDate filters on created_at.+// BackupListPosition is the keyset position ListBackups pages after: the sort+// time and ID of the last row the caller already holds.+type BackupListPosition struct {+ SortTime time.Time+ ID uuid.UUID+}++// BackupListFilter narrows ListBackups. An empty slice (or nil BeforeDate) is+// "no filter on that dimension". Types and Statuses match the synthetic columns+// the UNION projects ('WAL'/'COMPLETED' for WAL segments) and match any of their+// values; BeforeDate filters on created_at. The filter selects segments before+// they are grouped into WAL ranges.type BackupListFilter struct {Types []stringStatuses []stringdiff --git a/backend/internal/features/backups/backups/core/physical/service/service.go b/backend/internal/features/backups/backups/core/physical/service/service.goindex 6f7fa922..f72889fa 100644--- a/backend/internal/features/backups/backups/core/physical/service/service.go+++ b/backend/internal/features/backups/backups/core/physical/service/service.go@@ -470,53 +470,119 @@ func (s *PhysicalBackupService) GetLastBackupTimesByDatabaseIDs(return lastBackupTimes, nil}-// backupsUnionSubquery merges the FULL, incremental and committed-WAL tables into-// one result set with a common shape, projecting synthetic type ('FULL' /-// 'INCREMENTAL' / 'WAL') and, for WAL, a synthetic 'COMPLETED' status. The three-// database_id placeholders bind first; an outer WHERE (the list filter) and-// pagination wrap it. WAL ordering uses received_at as the row's created_at.-const backupsUnionSubquery = `- FROM (- SELECT id, 'FULL' AS type, status, timeline_id,- COALESCE(start_lsn::text, '') AS start_lsn,- COALESCE(stop_lsn::text, '') AS stop_lsn,- NULL::uuid AS root_full_backup_id,- NULL::uuid AS parent_incremental_backup_id,- NULL::text AS wal_filename,- COALESCE(backup_size_mb, 0) AS size_mb,- fail_message,- created_at, completed_at- FROM physical_full_backups- WHERE database_id = ?- UNION ALL- SELECT id, 'INCREMENTAL', status, timeline_id,- COALESCE(start_lsn::text, ''), COALESCE(stop_lsn::text, ''),- root_full_backup_id, parent_incremental_backup_id, NULL::text,- COALESCE(backup_size_mb, 0),- fail_message,- created_at, completed_at- FROM physical_incremental_backups- WHERE database_id = ?- UNION ALL- SELECT id, 'WAL', 'COMPLETED', timeline_id,- start_lsn::text, end_lsn::text,- NULL::uuid, NULL::uuid, wal_filename,- compressed_size_mb,- NULL::text,- received_at, NULL::timestamptz- FROM physical_wal_segments- WHERE database_id = ? AND file_name IS NOT NULL- ) backups`--// ListBackups returns one page of the database's backups — FULLs, incrementals-// and committed WAL segments merged into a single list newest-first by creation-// time (WAL ordered by received_at), optionally narrowed by filter. It UNIONs the-// three tables and paginates in SQL so a database with many WAL segments does not-// load its whole catalog per request. id breaks ties for a stable page boundary.+// backupListItemsQuery builds the newest-first list items. Committed WAL+// segments are grouped into ranges: a range ends at an LSN gap on its timeline,+// at a timeline switch, or where a FULL or INCREMENTAL row sits between two+// segments in created_at order. The gap flag is computed over every committed+// segment in LSN order before the filter applies, because received_at is set at+// claim time and concurrent uploads can order segments by time differently from+// their LSNs. The three database_id placeholders bind first, then the filter+// args.+func backupListItemsQuery(filterClause string) string {+ return `+ WITH committed_wal AS (+ SELECT id, timeline_id, start_lsn, end_lsn, wal_filename,+ compressed_size_mb, received_at,+ COALESCE(+ LAG(end_lsn) OVER (PARTITION BY timeline_id ORDER BY start_lsn) <> start_lsn,+ FALSE+ ) AS is_gap_start+ FROM physical_wal_segments+ WHERE database_id = ? AND file_name IS NOT NULL+ ),+ merged AS (+ SELECT id, 'FULL' AS type, status, timeline_id, start_lsn, stop_lsn,+ NULL::uuid AS root_full_backup_id,+ NULL::uuid AS parent_incremental_backup_id,+ NULL::text AS wal_filename,+ COALESCE(backup_size_mb, 0) AS size_mb,+ fail_message, created_at, completed_at,+ FALSE AS is_gap_start+ FROM physical_full_backups+ WHERE database_id = ?+ UNION ALL+ SELECT id, 'INCREMENTAL', status, timeline_id, start_lsn, stop_lsn,+ root_full_backup_id, parent_incremental_backup_id, NULL::text,+ COALESCE(backup_size_mb, 0),+ fail_message, created_at, completed_at,+ FALSE+ FROM physical_incremental_backups+ WHERE database_id = ?+ UNION ALL+ SELECT id, 'WAL', 'COMPLETED', timeline_id, start_lsn, end_lsn,+ NULL::uuid, NULL::uuid, wal_filename,+ compressed_size_mb,+ NULL::text, received_at, NULL::timestamptz,+ is_gap_start+ FROM committed_wal+ ),+ filtered AS (+ SELECT * FROM merged` + filterClause + `+ ),+ ordered AS (+ SELECT *,+ LAG(type) OVER time_order AS previous_type,+ LAG(timeline_id) OVER time_order AS previous_timeline_id+ FROM filtered+ WINDOW time_order AS (ORDER BY created_at, id)+ ),+ grouped AS (+ SELECT *,+ SUM(+ CASE+ WHEN type <> 'WAL'+ OR previous_type IS DISTINCT FROM 'WAL'+ OR previous_timeline_id <> timeline_id+ OR is_gap_start+ THEN 1 ELSE 0+ END+ ) OVER (ORDER BY created_at, id ROWS UNBOUNDED PRECEDING) AS group_id+ FROM ordered+ ),+ items AS (+ SELECT id, type, status, timeline_id,+ COALESCE(start_lsn::text, '') AS start_lsn,+ COALESCE(stop_lsn::text, '') AS stop_lsn,+ root_full_backup_id, parent_incremental_backup_id,+ NULL::text AS from_wal_filename,+ NULL::text AS to_wal_filename,+ NULL::int AS wal_segments_count,+ FALSE AS has_gap_before,+ size_mb, fail_message, created_at, completed_at,+ created_at AS sort_time+ FROM grouped+ WHERE type <> 'WAL'+ UNION ALL+ SELECT (ARRAY_AGG(id ORDER BY start_lsn))[1], 'WAL', 'COMPLETED', MIN(timeline_id),+ MIN(start_lsn)::text, MAX(stop_lsn)::text,+ NULL::uuid, NULL::uuid,+ (ARRAY_AGG(wal_filename ORDER BY start_lsn))[1],+ (ARRAY_AGG(wal_filename ORDER BY start_lsn DESC))[1],+ COUNT(*)::int,+ (ARRAY_AGG(is_gap_start ORDER BY start_lsn))[1],+ SUM(size_mb), NULL::text, MIN(created_at), MAX(created_at),+ MAX(created_at)+ FROM grouped+ WHERE type = 'WAL'+ GROUP BY group_id+ )+ SELECT id, type, status, timeline_id, start_lsn, stop_lsn,+ root_full_backup_id, parent_incremental_backup_id,+ from_wal_filename, to_wal_filename, wal_segments_count, has_gap_before,+ size_mb, fail_message, created_at, completed_at, sort_time+ FROM items`+}++// ListBackups returns up to limit list items for the database newest-first,+// optionally narrowed by filter and starting after the given position. It+// groups and pages in SQL so a database with many WAL segments never loads its+// whole catalog into the process. ID breaks sort-time ties for a stable page+// boundary.func (s *PhysicalBackupService) ListBackups(databaseID uuid.UUID,filter BackupListFilter,- limit, offset int,+ after *BackupListPosition,+ limit int,) ([]PhysicalBackupListRow, error) {var rows []PhysicalBackupListRow@@ -524,39 +590,23 @@ func (s *PhysicalBackupService) ListBackups(args := []any{databaseID, databaseID, databaseID}args = append(args, filterArgs...)- args = append(args, limit, offset)-- query := `- SELECT id, type, status, timeline_id, start_lsn, stop_lsn,- root_full_backup_id, parent_incremental_backup_id, wal_filename,- size_mb, fail_message, created_at, completed_at` +- backupsUnionSubquery + filterClause + `- ORDER BY created_at DESC, id DESC- LIMIT ? OFFSET ?`- err := storage.GetDb().Raw(query, args...).Scan(&rows).Error+ query := backupListItemsQuery(filterClause)- return rows, err-}--// CountBackups returns the number of backups (every type) for a database that-// match the same filter ListBackups uses — the denominator for pagination.-func (s *PhysicalBackupService) CountBackups(- databaseID uuid.UUID,- filter BackupListFilter,-) (int64, error) {- var total int64-- filterClause, filterArgs := filter.buildClause()-- args := []any{databaseID, databaseID, databaseID}- args = append(args, filterArgs...)+ if after != nil {+ query += `+ WHERE (sort_time, id) < (?, ?)`+ args = append(args, after.SortTime, after.ID)+ }- query := `SELECT COUNT(*)` + backupsUnionSubquery + filterClause+ query += `+ ORDER BY sort_time DESC, id DESC+ LIMIT ?`+ args = append(args, limit)- err := storage.GetDb().Raw(query, args...).Scan(&total).Error+ err := storage.GetDb().Raw(query, args...).Scan(&rows).Error- return total, err+ return rows, err}// findNextAnchorLSNAfter returns the smallest start_lsn among the database'sdiff --git a/backend/internal/features/backups/backups/dto/physical/dto.go b/backend/internal/features/backups/backups/dto/physical/dto.goindex 510486d9..fd3bae6b 100644--- a/backend/internal/features/backups/backups/dto/physical/dto.go+++ b/backend/internal/features/backups/backups/dto/physical/dto.go@@ -9,10 +9,11 @@ import ()// PhysicalBackupListItem is one row of the flat physical-backup list: a FULL, an-// incremental, or a committed WAL segment. The backend returns all three types-// in a single list sorted by createdAt; the frontend filters by Type. Type-only-// fields (chain links for incrementals, WalFilename for WAL) are pointers so an-// unrelated row omits them rather than emitting a misleading zero value.+// incremental, or a WAL range of consecutive committed segments. Type-only+// fields (chain links for incrementals, the range summary for WAL) are pointers+// so an unrelated row omits them rather than emitting a misleading zero value.+// A WAL range's CreatedAt and CompletedAt are the receive times of its first and+// last segments.type PhysicalBackupListItem struct {ID uuid.UUID `json:"id"`Type physical_enums.PhysicalBackupType `json:"type"`@@ -26,8 +27,13 @@ type PhysicalBackupListItem struct {RootFullBackupID *uuid.UUID `json:"rootFullBackupId,omitempty"`ParentIncrementalBackupID *uuid.UUID `json:"parentIncrementalBackupId,omitempty"`- // WalFilename is the bare PG segment name, WAL rows only.- WalFilename *string `json:"walFilename,omitempty"`+ // WAL range summary, WAL rows only. HasGapBefore is true when an older+ // committed segment exists on the same timeline and the range does not start+ // where it ended.+ FromWalFilename *string `json:"fromWalFilename,omitempty"`+ ToWalFilename *string `json:"toWalFilename,omitempty"`+ WalSegmentsCount *int `json:"walSegmentsCount,omitempty"`+ HasGapBefore bool `json:"hasGapBefore,omitzero"`SizeMb float64 `json:"sizeMb"`@@ -43,10 +49,11 @@ type PhysicalBackupListItem struct {// page can be all one type). Types/Statuses are optional and repeatable - a row// matches when its type (or status) is any of the given values, and the two// dimensions combine with AND. BeforeDate keeps only backups created strictly-// before it.+// before it. Cursor is the NextCursor of the previous page; omit it for the+// first page.type GetPhysicalBackupsRequest struct {Limit int `form:"limit"`- Offset int `form:"offset"`+ Cursor string `form:"cursor"`Types []physical_enums.PhysicalBackupType `form:"type"`Statuses []string `form:"status"`BeforeDate *time.Time `form:"beforeDate"`@@ -56,11 +63,8 @@ type GetPhysicalBackupsResponse struct {Backups []PhysicalBackupListItem `json:"backups"`TotalUsageMb float64 `json:"totalUsageMb"`- // Total is the count of all backups (every type) for the database, for- // driving pagination; Limit/Offset echo the page that was served.- Total int64 `json:"total"`- Limit int `json:"limit"`- Offset int `json:"offset"`+ // NextCursor continues the list after this page; empty on the last page.+ NextCursor string `json:"nextCursor,omitzero"`}// TriggerBackupType selects which backup the trigger endpoint requests.diff --git a/backend/internal/features/backups/backups/services/physical_list_cursor.go b/backend/internal/features/backups/backups/services/physical_list_cursor.gonew file mode 100644index 00000000..4fa0be53--- /dev/null+++ b/backend/internal/features/backups/backups/services/physical_list_cursor.go@@ -0,0 +1,51 @@+package backups_services++import (+ "encoding/base64"+ "encoding/json"+ "time"++ "github.com/google/uuid"++ physical_core_service "databasus-backend/internal/features/backups/backups/core/physical/service"+)++// physicalListCursor is the JSON body of the opaque page cursor. It carries only+// a position in the list: the database always comes from the request path and+// passes the access check, so a cursor taken from another database selects+// nothing of that database.+type physicalListCursor struct {+ SortTime time.Time `json:"t"`+ ID uuid.UUID `json:"id"`+}++func encodePhysicalListCursor(position physical_core_service.BackupListPosition) (string, error) {+ cursorJSON, err := json.Marshal(physicalListCursor{SortTime: position.SortTime, ID: position.ID})+ if err != nil {+ return "", err+ }++ return base64.RawURLEncoding.EncodeToString(cursorJSON), nil+}++func decodePhysicalListCursor(encodedCursor string) (*physical_core_service.BackupListPosition, error) {+ if encodedCursor == "" {+ return nil, nil+ }++ cursorJSON, err := base64.RawURLEncoding.DecodeString(encodedCursor)+ if err != nil {+ return nil, ErrInvalidBackupsCursor+ }++ var cursor physicalListCursor+ if err := json.Unmarshal(cursorJSON, &cursor); err != nil {+ return nil, ErrInvalidBackupsCursor+ }++ if cursor.SortTime.IsZero() || cursor.ID == uuid.Nil {+ return nil, ErrInvalidBackupsCursor+ }++ return &physical_core_service.BackupListPosition{SortTime: cursor.SortTime, ID: cursor.ID}, nil+}diff --git a/backend/internal/features/backups/backups/services/physical_service.go b/backend/internal/features/backups/backups/services/physical_service.goindex a7f3ece4..21c74122 100644--- a/backend/internal/features/backups/backups/services/physical_service.go+++ b/backend/internal/features/backups/backups/services/physical_service.go@@ -33,6 +33,10 @@ import (// no chain can take one — the caller must run a full first.var ErrNoExtendableChain = errors.New("no extendable chain; run a full backup first")+// ErrInvalidBackupsCursor is returned when a backup list request carries a+// cursor the server did not issue or cannot decode.+var ErrInvalidBackupsCursor = errors.New("invalid backups cursor")+// ErrBackupNotFound is returned when a backup id matches no FULL, incremental,// or WAL row owned by a database the user can access.var ErrBackupNotFound = errors.New("backup not found")@@ -67,10 +71,11 @@ type PhysicalBackupService struct {}// GetBackups returns one page of a database's backups — FULLs, incrementals and-// committed WAL segments — as one flat list sorted newest-first by creation-// time. Pagination (limit/offset, with a Total for the page count) happens in-// SQL so a database with many WAL segments never loads its whole catalog. The-// aggregate on-disk usage rides along so the UI need not sum it.+// WAL ranges of consecutive committed segments — as one flat list sorted+// newest-first. It pages by keyset cursor rather than offset because the newest+// WAL range grows and new backups appear at the top between requests, which+// would shift offsets. One extra row is fetched to know whether a next page+// exists. The aggregate on-disk usage rides along so the UI need not sum it.func (s *PhysicalBackupService) GetBackups(ctx context.Context,user *users_models.User,@@ -82,15 +87,14 @@ func (s *PhysicalBackupService) GetBackups(}limit := normalizeBackupsPageLimit(request.Limit)- offset := max(request.Offset, 0)filter := toBackupListFilter(request)- rows, err := s.physicalCoreService.ListBackups(databaseID, filter, limit, offset)+ after, err := decodePhysicalListCursor(request.Cursor)if err != nil {return nil, err}- total, err := s.physicalCoreService.CountBackups(databaseID, filter)+ rows, err := s.physicalCoreService.ListBackups(databaseID, filter, after, limit+1)if err != nil {return nil, err}@@ -100,18 +104,34 @@ func (s *PhysicalBackupService) GetBackups(return nil, err}+ hasNextPage := len(rows) > limit+ if hasNextPage {+ rows = rows[:limit]+ }+items := make([]backups_dto_physical.PhysicalBackupListItem, 0, len(rows))for _, row := range rows {items = append(items, rowToListItem(row))}- return &backups_dto_physical.GetPhysicalBackupsResponse{+ response := &backups_dto_physical.GetPhysicalBackupsResponse{Backups: items,TotalUsageMb: totalUsageMb,- Total: total,- Limit: limit,- Offset: offset,- }, nil+ }++ if hasNextPage {+ lastRow := rows[len(rows)-1]++ response.NextCursor, err = encodePhysicalListCursor(physical_core_service.BackupListPosition{+ SortTime: lastRow.SortTime,+ ID: lastRow.ID,+ })+ if err != nil {+ return nil, err+ }+ }++ return response, nil}// RequestBackup triggers the backup the scheduler would naturally pick next:@@ -584,7 +604,10 @@ func rowToListItem(row physical_core_service.PhysicalBackupListRow) backups_dto_StopLSN: row.StopLSN,RootFullBackupID: row.RootFullBackupID,ParentIncrementalBackupID: row.ParentIncrementalBackupID,- WalFilename: row.WalFilename,+ FromWalFilename: row.FromWalFilename,+ ToWalFilename: row.ToWalFilename,+ WalSegmentsCount: row.WalSegmentsCount,+ HasGapBefore: row.HasGapBefore,SizeMb: row.SizeMb,FailMessage: row.FailMessage,CreatedAt: row.CreatedAt,diff --git a/backend/internal/features/tests/physical/postgresql/shared/bodies.go b/backend/internal/features/tests/physical/postgresql/shared/bodies.goindex 787c3b7f..b5577f7a 100644--- a/backend/internal/features/tests/physical/postgresql/shared/bodies.go+++ b/backend/internal/features/tests/physical/postgresql/shared/bodies.go@@ -162,7 +162,7 @@ func RunWalStreamCatalogsHistoryOnTimelineSwitch(t *testing.T, version, image stchain := waitForChainBackups(t, router, fixture, 0, 3*time.Minute)// Stream a couple of committed TL1 segments so the slot is actively consuming when we promote.- streamPostFullSegments(t, ctx, router, primaryConn, fixture, chainTipStopLSN(t, chain), 2, 90*time.Second)+ streamPostFullSegments(t, ctx, primaryConn, fixture, chain, 2, 90*time.Second)// Promote: the standby becomes a primary on timeline 2. pg_receivewal follows the switch and// uploads 00000002.history, driving the issue #643 path in the live supervisor.@@ -325,11 +325,10 @@ func RunWhenWalGapBeforeTargetTokenRequestReturns422(t *testing.T, version, imagenablePhysicalBackupsViaAPI(t, router, fixture, true)chain := waitForChainBackups(t, router, fixture, 0, 3*time.Minute)- fullStopLSN := chainTipStopLSN(t, chain)// Stream a run of post-FULL segments, then drop a committed middle one so a// real hole sits in the replayable WAL ahead of the target.- postFull := streamPostFullSegments(t, ctx, router, sourceConn, fixture, fullStopLSN, 3, 90*time.Second)+ postFull := streamPostFullSegments(t, ctx, sourceConn, fixture, chain, 3, 90*time.Second)removed := postFull[len(postFull)/2]require.NoError(t, physical_repositories.GetWalSegmentRepository().DeleteByID(removed.ID))@@ -377,7 +376,7 @@ func RunWhenOrphanSweepRunsAfterFullTargetPastFullStaysRestorable(t *testing.T,chain := waitForChainBackups(t, router, fixture, 0, 3*time.Minute)insertMarker(t, ctx, sourceConn, "after-full", "row-replayed-up-to-target")- streamPostFullSegments(t, ctx, router, sourceConn, fixture, chainTipStopLSN(t, chain), 2, 90*time.Second)+ streamPostFullSegments(t, ctx, sourceConn, fixture, chain, 2, 90*time.Second)// A margin wider than the whole-second recovery_target_time truncation on either side keeps the// target unambiguously inside the streamed range.diff --git a/backend/internal/features/tests/physical/postgresql/shared/helpers.go b/backend/internal/features/tests/physical/postgresql/shared/helpers.goindex 572bec41..8ae09d79 100644--- a/backend/internal/features/tests/physical/postgresql/shared/helpers.go+++ b/backend/internal/features/tests/physical/postgresql/shared/helpers.go@@ -666,57 +666,61 @@ func downloadRestoreBundleViaAPI(return hostPath}-// committedWalSegmentsInOrder lists the database's committed (uploaded) WAL-// segments through the flat backup API (type=WAL) and returns them ordered by-// start_lsn ascending. The WAL union only emits rows whose file is uploaded, so-// every listed row is committed — no extra filtering needed.+// committedWalSegmentsInOrder reads the database's committed (uploaded) WAL+// segments on one timeline from the catalog, ordered by start_lsn ascending. The+// backup list API groups segments into ranges, so it cannot hand out a single+// segment to delete.func committedWalSegmentsInOrder(t *testing.T,- router *gin.Engine,fixture *postgresql_executor.PhysicalDBFixture,-) []backups_dto_physical.PhysicalBackupListItem {+ timelineID int,+) []*physical_models.PhysicalWalSegment {t.Helper()- segments := listBackupsByType(t, router, fixture, physical_enums.PhysicalBackupTypeWal)+ segments, err := physical_repositories.GetWalSegmentRepository().FindByChainSpan(+ fixture.DB.ID, timelineID, walmath.LSN(0), chain_view.LSNMax,+ )+ require.NoError(t, err)- slices.SortFunc(segments, func(a, b backups_dto_physical.PhysicalBackupListItem) int {- return cmp.Compare(parseLSN(t, a.StartLSN), parseLSN(t, b.StartLSN))+ return slices.DeleteFunc(segments, func(segment *physical_models.PhysicalWalSegment) bool {+ return segment.FileName == nil})-- return segments}// streamPostFullSegments forces WAL rotations until at least minCount committed-// segments lie past fullStopLSN (i.e. in the replayable range after the FULL),-// returning them ordered by start_lsn. pg_receivewal writes full, contiguous-// segments, so the run has no gap until a caller deletes one.+// segments lie past the chain tip's stop_lsn on its timeline (i.e. in the+// replayable range after the tip), returning them ordered by start_lsn.+// pg_receivewal writes full, contiguous segments, so the run has no gap until a+// caller deletes one.func streamPostFullSegments(t *testing.T,ctx context.Context,- router *gin.Engine,conn *pgx.Conn,fixture *postgresql_executor.PhysicalDBFixture,- fullStopLSN walmath.LSN,+ chain []backups_dto_physical.PhysicalBackupListItem,minCount int,timeout time.Duration,-) []backups_dto_physical.PhysicalBackupListItem {+) []*physical_models.PhysicalWalSegment {t.Helper()+ tipStopLSN := chainTipStopLSN(t, chain)+ tipTimelineID := chain[len(chain)-1].TimelineID+deadline := time.Now().UTC().Add(timeout)for time.Now().UTC().Before(deadline) {_, err := postgresql_executor.ForceWalRotation(ctx, conn)require.NoError(t, err)- var postFull []backups_dto_physical.PhysicalBackupListItem- for _, segment := range committedWalSegmentsInOrder(t, router, fixture) {- if parseLSN(t, segment.StopLSN) > fullStopLSN {- postFull = append(postFull, segment)+ var postTipSegments []*physical_models.PhysicalWalSegment+ for _, segment := range committedWalSegmentsInOrder(t, fixture, tipTimelineID) {+ if segment.EndLSN > tipStopLSN {+ postTipSegments = append(postTipSegments, segment)}}- if len(postFull) >= minCount {- return postFull+ if len(postTipSegments) >= minCount {+ return postTipSegments}time.Sleep(250 * time.Millisecond)diff --git a/frontend/src/entity/backups/physical/api/physicalBackupsApi.ts b/frontend/src/entity/backups/physical/api/physicalBackupsApi.tsindex addfff20..8a4137e4 100644--- a/frontend/src/entity/backups/physical/api/physicalBackupsApi.ts+++ b/frontend/src/entity/backups/physical/api/physicalBackupsApi.ts@@ -13,12 +13,12 @@ export const physicalBackupsApi = {async getPhysicalBackups(databaseId: string,limit?: number,- offset?: number,+ cursor?: string,filters?: PhysicalBackupsFilters,) {const params = new URLSearchParams();if (limit !== undefined) params.append('limit', limit.toString());- if (offset !== undefined) params.append('offset', offset.toString());+ if (cursor !== undefined) params.append('cursor', cursor);if (filters?.types) for (const type of filters.types) params.append('type', type);if (filters?.statuses) for (const status of filters.statuses) params.append('status', status);diff --git a/frontend/src/entity/backups/physical/model/GetPhysicalBackupsResponse.ts b/frontend/src/entity/backups/physical/model/GetPhysicalBackupsResponse.tsindex 5a16734c..3fbe9096 100644--- a/frontend/src/entity/backups/physical/model/GetPhysicalBackupsResponse.ts+++ b/frontend/src/entity/backups/physical/model/GetPhysicalBackupsResponse.ts@@ -4,9 +4,6 @@ export interface GetPhysicalBackupsResponse {backups: PhysicalBackupListItem[];totalUsageMb: number;- // total counts every backup type for the database (drives pagination); limit and- // offset echo the page that was served- total: number;- limit: number;- offset: number;+ // continues the list after this page; absent on the last page+ nextCursor?: string;}diff --git a/frontend/src/entity/backups/physical/model/PhysicalBackupListItem.ts b/frontend/src/entity/backups/physical/model/PhysicalBackupListItem.tsindex 7dd3c662..db0b6c30 100644--- a/frontend/src/entity/backups/physical/model/PhysicalBackupListItem.ts+++ b/frontend/src/entity/backups/physical/model/PhysicalBackupListItem.ts@@ -1,10 +1,11 @@import type { PhysicalBackupStatus } from './PhysicalBackupStatus';import type { PhysicalBackupType } from './PhysicalBackupType';-// One row of the flat physical-backup list: a FULL, an incremental, or a committed-// WAL segment. Type-only fields are optional so unrelated rows omit them rather-// than carrying a misleading zero value (chain links exist on incrementals only,-// walFilename on WAL only).+// One row of the flat physical-backup list: a FULL, an incremental, or a WAL range+// of consecutive committed segments. Type-only fields are optional so unrelated+// rows omit them rather than carrying a misleading zero value (chain links exist+// on incrementals only, the range summary on WAL only). A WAL range's createdAt+// and completedAt are the receive times of its first and last segments.export interface PhysicalBackupListItem {id: string;type: PhysicalBackupType;@@ -18,8 +19,13 @@ export interface PhysicalBackupListItem {rootFullBackupId?: string;parentIncrementalBackupId?: string;- // bare PostgreSQL segment name, WAL rows only- walFilename?: string;+ // WAL range summary, WAL rows only: the first and last segment names and how+ // many segments the range holds. hasGapBefore marks a missing segment between+ // this range and the older one on the same timeline.+ fromWalFilename?: string;+ toWalFilename?: string;+ walSegmentsCount?: number;+ hasGapBefore?: boolean;sizeMb: number;diff --git a/frontend/src/features/backups/logical/ui/LogicalBackupsComponent.tsx b/frontend/src/features/backups/logical/ui/LogicalBackupsComponent.tsxindex f18c1d51..0cd2d90e 100644--- a/frontend/src/features/backups/logical/ui/LogicalBackupsComponent.tsx+++ b/frontend/src/features/backups/logical/ui/LogicalBackupsComponent.tsx@@ -16,7 +16,7 @@ import { App, Button, Modal, Spin, Table, Tooltip } from 'antd';import type { ColumnsType } from 'antd/es/table';import dayjs from 'dayjs';import type { TFunction } from 'i18next';-import { type JSX, useEffect, useRef, useState } from 'react';+import { type JSX, useEffect, useState } from 'react';import { Trans, useTranslation } from 'react-i18next';import {@@ -33,7 +33,7 @@ import {import { BackupEncryption } from '../../../../entity/backups/shared';import { type Database, DatabaseType } from '../../../../entity/databases';import { verificationRunsApi } from '../../../../entity/verification/runs';-import { usePersistentState } from '../../../../shared/hooks';+import { usePersistentState, usePolledPagedList } from '../../../../shared/hooks';import {type TranslationKey,getWebsitePageUrl,@@ -48,6 +48,7 @@ import { RESTORE_VERIFICATION_STATUS_BADGE_STYLES } from '../model/restoreVerifiimport { LogicalBackupsFiltersPanelComponent } from './LogicalBackupsFiltersPanelComponent';const BACKUPS_PAGE_SIZE = 50;+const BACKUPS_REFRESH_MS = 1_000;// Physical databases have their own backups list; the generic text keeps the map exhaustive.const DOWNLOAD_TOOLTIP_KEYS: Record<DatabaseType, TranslationKey> = {@@ -100,14 +101,6 @@ export const LogicalBackupsComponent = ({const { t } = useTranslation();const { locale, formatNumber, formatRelativeTime } = useLocale();const { message, modal } = App.useApp();- const [isBackupsLoading, setIsBackupsLoading] = useState(false);- const [backups, setBackups] = useState<LogicalBackup[]>([]);-- const [totalBackups, setTotalBackups] = useState(0);- const [currentLimit, setCurrentLimit] = useState(BACKUPS_PAGE_SIZE);- const [isLoadingMore, setIsLoadingMore] = useState(false);- const [hasMore, setHasMore] = useState(true);-const [backupConfig, setBackupConfig] = useState<LogicalBackupConfig | undefined>();const [isBackupConfigLoading, setIsBackupConfigLoading] = useState(false);@@ -120,9 +113,6 @@ export const LogicalBackupsComponent = ({const [showingRestoresBackupId, setShowingRestoresBackupId] = useState<string | undefined>();- const lastRequestTimeRef = useRef<number>(0);- const isBackupsRequestInFlightRef = useRef(false);-const [downloadingBackupId, setDownloadingBackupId] = useState<string | undefined>();const [cancellingBackupId, setCancellingBackupId] = useState<string | undefined>();const [verifyingBackupId, setVerifyingBackupId] = useState<string | undefined>();@@ -141,61 +131,21 @@ export const LogicalBackupsComponent = ({}};- const loadBackups = async (limit?: number, filtersOverride?: BackupsFilters) => {- if (isBackupsRequestInFlightRef.current) return;- isBackupsRequestInFlightRef.current = true;-- const requestTime = Date.now();- lastRequestTimeRef.current = requestTime;-- const loadLimit = limit ?? currentLimit;- const activeFilters = filtersOverride ?? filters;-- try {- const response = await logicalBackupsApi.getBackups(database.id, loadLimit, 0, activeFilters);-- if (lastRequestTimeRef.current !== requestTime) return;-- setBackups(response.backups);- setTotalBackups(response.total);- setHasMore(response.backups.length < response.total);- } catch (e) {- if (lastRequestTimeRef.current === requestTime) {- alert(translateApiError(e, t));- }- } finally {- isBackupsRequestInFlightRef.current = false;- }- };-- const loadMoreBackups = async () => {- if (isLoadingMore || !hasMore) {- return;- }-- setIsLoadingMore(true);-- const newLimit = currentLimit + BACKUPS_PAGE_SIZE;- setCurrentLimit(newLimit);-- const requestTime = Date.now();- lastRequestTimeRef.current = requestTime;-- try {- const response = await logicalBackupsApi.getBackups(database.id, newLimit, 0, filters);-- if (lastRequestTimeRef.current !== requestTime) return;+ const fetchBackupsPage = async (offset: number | undefined) => {+ const pageOffset = offset ?? 0;+ const response = await logicalBackupsApi.getBackups(+ database.id,+ BACKUPS_PAGE_SIZE,+ pageOffset,+ filters,+ );- setBackups(response.backups);- setTotalBackups(response.total);- setHasMore(response.backups.length < response.total);- } catch (e) {- if (lastRequestTimeRef.current === requestTime) {- alert(translateApiError(e, t));- }- }+ const loadedCount = pageOffset + response.backups.length;- setIsLoadingMore(false);+ return {+ items: response.backups,+ nextCursor: loadedCount < response.total ? loadedCount : undefined,+ };};const makeBackup = async () => {@@ -204,9 +154,7 @@ export const LogicalBackupsComponent = ({try {await logicalBackupsApi.makeBackup(database.id);await new Promise((resolve) => setTimeout(resolve, 1000));- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);- await loadBackups(BACKUPS_PAGE_SIZE);+ await reloadBackups();} catch (e) {alert(translateApiError(e, t));}@@ -224,9 +172,7 @@ export const LogicalBackupsComponent = ({try {await logicalBackupsApi.deleteBackup(deleteConfimationId);- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);- await loadBackups(BACKUPS_PAGE_SIZE);+ await reloadBackups();} catch (e) {alert(translateApiError(e, t));}@@ -240,7 +186,7 @@ export const LogicalBackupsComponent = ({try {await logicalBackupsApi.cancelBackup(backupId);- await loadBackups();+ await refreshBackups();} catch (e) {alert(translateApiError(e, t));}@@ -290,63 +236,37 @@ export const LogicalBackupsComponent = ({});};+ const {+ items: backups,+ isLoading: isBackupsLoading,+ isLoadingMore,+ hasMore,+ reload: reloadBackups,+ refreshFirstPage: refreshBackups,+ } = usePolledPagedList({+ fetchPage: fetchBackupsPage,+ getItemKey: (backup: LogicalBackup) => backup.id,+ refreshIntervalMs: BACKUPS_REFRESH_MS,+ scrollContainerRef,+ resetKey: JSON.stringify([database.id, filters]),+ onError: (e) => alert(translateApiError(e, t)),+ });+useEffect(() => {setIsBackupConfigLoading(true);- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);logicalBackupConfigApi.getBackupConfigByDbID(database.id).then((config) => {setBackupConfig(config);setIsBackupConfigLoading(false);-- setIsBackupsLoading(true);- loadBackups(BACKUPS_PAGE_SIZE).then(() => setIsBackupsLoading(false));});-- return () => {};}, [database]);- useEffect(() => {- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);- setIsBackupsLoading(true);- loadBackups(BACKUPS_PAGE_SIZE, filters).then(() => setIsBackupsLoading(false));- }, [filters]);-- useEffect(() => {- const intervalId = setInterval(() => {- loadBackups();- }, 1_000);-- return () => clearInterval(intervalId);- }, [currentLimit, filters]);-useEffect(() => {if (downloadingBackupId) {downloadBackup(downloadingBackupId);}}, [downloadingBackupId]);- useEffect(() => {- if (!scrollContainerRef?.current) {- return;- }-- const handleScroll = () => {- if (!scrollContainerRef.current) return;-- const { scrollTop, scrollHeight, clientHeight } = scrollContainerRef.current;-- if (scrollHeight - scrollTop <= clientHeight + 100 && hasMore && !isLoadingMore) {- loadMoreBackups();- }- };-- const container = scrollContainerRef.current;- container.addEventListener('scroll', handleScroll);- return () => container.removeEventListener('scroll', handleScroll);- }, [hasMore, isLoadingMore, currentLimit, scrollContainerRef]);-const renderBackupStatusLabel = (status: LogicalBackupStatus, record: LogicalBackup) => {if (status === LogicalBackupStatus.FAILED) {return (@@ -718,7 +638,7 @@ export const LogicalBackupsComponent = ({)}{!hasMore && backups.length > 0 && (<div className="mt-3 text-center text-sm text-gray-500 dark:text-gray-400">- {t('backups.list.allLoaded', { count: totalBackups })}+ {t('backups.list.allLoaded', { count: backups.length })}</div>)}{!isBackupsLoading && backups.length === 0 && (@@ -746,7 +666,7 @@ export const LogicalBackupsComponent = ({)}{!hasMore && backups.length > 0 && (<div className="mt-2 text-center text-gray-500 dark:text-gray-400">- {t('backups.list.allLoaded', { count: totalBackups })}+ {t('backups.list.allLoaded', { count: backups.length })}</div>)}</div>diff --git a/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.test.tsx b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.test.tsxnew file mode 100644index 00000000..d8f7e16c--- /dev/null+++ b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.test.tsx@@ -0,0 +1,87 @@+import { renderToStaticMarkup } from 'react-dom/server';+import { describe, expect, it, vi } from 'vitest';++import {+ type PhysicalBackupListItem,+ PhysicalBackupStatus,+ PhysicalBackupType,+} from '../../../../entity/backups/physical';+import { LocaleProvider } from '../../../../shared/i18n';+import { PhysicalBackupTypeCellComponent } from './PhysicalBackupTypeCellComponent';++// The entity's public API imports its API client, and the client's config+// module reads window at import time. The tests run in node, so they supply+// window. LocaleProvider then reads localStorage, which here reports no saved+// language.+vi.hoisted(() => {+ vi.stubGlobal('window', {});+ vi.stubGlobal('localStorage', { getItem: () => null });+ vi.stubGlobal('navigator', { language: 'en-US', languages: ['en-US'] });+});++const FIRST_SEGMENT = '000000010000000000000010';+const LAST_SEGMENT = '0000000100000000000000FF';++const createWalRange = (change: Partial<PhysicalBackupListItem>): PhysicalBackupListItem => ({+ id: 'range-id',+ type: PhysicalBackupType.WAL,+ status: PhysicalBackupStatus.COMPLETED,+ timelineId: 1,+ startLsn: '0/10000000',+ stopLsn: '1/0',+ fromWalFilename: FIRST_SEGMENT,+ toWalFilename: LAST_SEGMENT,+ walSegmentsCount: 240,+ hasGapBefore: false,+ sizeMb: 3840,+ createdAt: new Date('2026-10-10T03:00:00Z'),+ completedAt: new Date('2026-10-10T09:12:00Z'),+ ...change,+});++const renderCell = (backup: PhysicalBackupListItem) =>+ renderToStaticMarkup(+ <LocaleProvider>+ <PhysicalBackupTypeCellComponent backup={backup} />+ </LocaleProvider>,+ );++describe('PhysicalBackupTypeCellComponent', () => {+ it('shows the segment count and the first and last segment of a WAL range', () => {+ const markup = renderCell(createWalRange({}));++ expect(markup).toContain('Segments: 240');+ expect(markup).toContain(FIRST_SEGMENT);+ expect(markup).toContain(LAST_SEGMENT);+ expect(markup).not.toContain('Gap before this range');+ });++ it('marks a WAL range that follows a gap', () => {+ const markup = renderCell(createWalRange({ hasGapBefore: true }));++ expect(markup).toContain('Gap before this range');+ });++ it('shows one segment name for a single-segment range', () => {+ const markup = renderCell(+ createWalRange({ toWalFilename: FIRST_SEGMENT, walSegmentsCount: 1 }),+ );++ expect(markup.split(FIRST_SEGMENT)).toHaveLength(2);+ expect(markup).toContain('Segments: 1');+ });++ it('shows only the type badge for a backup', () => {+ const markup = renderCell(+ createWalRange({+ type: PhysicalBackupType.FULL,+ fromWalFilename: undefined,+ toWalFilename: undefined,+ walSegmentsCount: undefined,+ }),+ );++ expect(markup).toContain('Full');+ expect(markup).not.toContain('Segments:');+ });+});diff --git a/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.tsx b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.tsxnew file mode 100644index 00000000..243cde4b--- /dev/null+++ b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.tsx@@ -0,0 +1,82 @@+import { ArrowRightOutlined } from '@ant-design/icons';+import { Tooltip } from 'antd';+import type { TFunction } from 'i18next';+import type { JSX } from 'react';+import { useTranslation } from 'react-i18next';++import {+ PHYSICAL_BACKUP_TYPE_LABEL_KEYS,+ type PhysicalBackupListItem,+ PhysicalBackupType,+} from '../../../../entity/backups/physical';++interface Props {+ backup: PhysicalBackupListItem;+}++const renderTypeBadge = (type: PhysicalBackupType, t: TFunction): JSX.Element => {+ const label = t(PHYSICAL_BACKUP_TYPE_LABEL_KEYS[type]);++ if (type === PhysicalBackupType.FULL) {+ return (+ <span className="inline-flex items-center rounded bg-indigo-500/15 px-2 py-0.5 text-xs font-semibold text-indigo-700 ring-1 ring-indigo-500/40 ring-inset dark:text-indigo-300">+ {label}+ </span>+ );+ }++ if (type === PhysicalBackupType.WAL) {+ return (+ <span className="inline-flex items-center rounded bg-slate-400/10 px-2 py-0.5 text-xs font-medium text-slate-600 ring-1 ring-slate-400/30 ring-inset dark:text-slate-300">+ {label}+ </span>+ );+ }++ return (+ <span className="inline-flex items-center rounded bg-indigo-400/10 px-2 py-0.5 text-xs font-medium text-indigo-600 ring-1 ring-indigo-400/30 ring-inset dark:text-indigo-300">+ {label}+ </span>+ );+};++export const PhysicalBackupTypeCellComponent = ({ backup }: Props): JSX.Element => {+ const { t } = useTranslation();++ const typeBadge = renderTypeBadge(backup.type, t);++ if (backup.type !== PhysicalBackupType.WAL) {+ return typeBadge;+ }++ const isSingleSegment = backup.fromWalFilename === backup.toWalFilename;++ return (+ <div className="space-y-1">+ <div className="flex items-center gap-2">+ {typeBadge}+ <span className="text-xs text-gray-500 dark:text-gray-400">+ {t('backups.physical.list.walRange.segments', { count: backup.walSegmentsCount })}+ </span>+ </div>++ <div className="flex flex-wrap items-center gap-1 font-mono text-xs text-gray-600 dark:text-gray-300">+ {backup.fromWalFilename}+ {!isSingleSegment && (+ <>+ <ArrowRightOutlined className="text-[10px]" />+ {backup.toWalFilename}+ </>+ )}+ </div>++ {backup.hasGapBefore && (+ <Tooltip title={t('backups.physical.list.walRange.gapBeforeTooltip')}>+ <span className="inline-flex items-center rounded bg-amber-500/15 px-2 py-0.5 text-xs font-medium text-amber-700 ring-1 ring-amber-500/40 ring-inset dark:text-amber-300">+ {t('backups.physical.list.walRange.gapBefore')}+ </span>+ </Tooltip>+ )}+ </div>+ );+};diff --git a/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsx b/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsxindex a4033fb1..f0ae530d 100644--- a/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsx+++ b/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsx@@ -1,4 +1,5 @@import {+ ArrowRightOutlined,CloseCircleOutlined,CloudUploadOutlined,DeleteOutlined,@@ -11,12 +12,11 @@ import { App, Button, Dropdown, type MenuProps, Modal, Spin, Table, Tooltip } frimport type { ColumnsType } from 'antd/es/table';import dayjs from 'dayjs';import type { TFunction } from 'i18next';-import { type JSX, useEffect, useRef, useState } from 'react';+import { type JSX, useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';import {PHYSICAL_BACKUP_STATUS_LABEL_KEYS,- PHYSICAL_BACKUP_TYPE_LABEL_KEYS,type PhysicalBackupConfig,type PhysicalBackupListItem,PhysicalBackupStatus,@@ -27,16 +27,18 @@ import {physicalBackupsApi,} from '../../../../entity/backups/physical';import { type Database, PhysicalDatabaseBackupType } from '../../../../entity/databases';-import { usePersistentState } from '../../../../shared/hooks';+import { usePersistentState, usePolledPagedList } from '../../../../shared/hooks';import { type LocaleContextValue, translateApiError, useLocale } from '../../../../shared/i18n';import { formatDuration } from '../../../../shared/lib';import { getUserTimeFormat } from '../../../../shared/time';import { ConfirmationComponent } from '../../../../shared/ui';import { PHYSICAL_BACKUP_STATUS_BADGE_STYLES } from '../model/physicalBackupStatus';+import { PhysicalBackupTypeCellComponent } from './PhysicalBackupTypeCellComponent';import { PhysicalBackupsFiltersPanelComponent } from './PhysicalBackupsFiltersPanelComponent';import { PhysicalRestoreComponent } from './PhysicalRestoreComponent';const BACKUPS_PAGE_SIZE = 50;+const BACKUPS_REFRESH_MS = 1_000;interface Props {database: Database;@@ -88,32 +90,6 @@ const renderStatusBadge = ();};-const renderTypeBadge = (type: PhysicalBackupType, t: TFunction): JSX.Element => {- const label = t(PHYSICAL_BACKUP_TYPE_LABEL_KEYS[type]);-- if (type === PhysicalBackupType.FULL) {- return (- <span className="inline-flex items-center rounded bg-indigo-500/15 px-2 py-0.5 text-xs font-semibold text-indigo-700 ring-1 ring-indigo-500/40 ring-inset dark:text-indigo-300">- {label}- </span>- );- }-- if (type === PhysicalBackupType.WAL) {- return (- <span className="inline-flex items-center rounded bg-slate-400/10 px-2 py-0.5 text-xs font-medium text-slate-600 ring-1 ring-slate-400/30 ring-inset dark:text-slate-300">- {label}- </span>- );- }-- return (- <span className="inline-flex items-center rounded bg-indigo-400/10 px-2 py-0.5 text-xs font-medium text-indigo-600 ring-1 ring-indigo-400/30 ring-inset dark:text-indigo-300">- {label}- </span>- );-};-export const PhysicalBackupsComponent = ({database,isCanManageDBs,@@ -124,15 +100,8 @@ export const PhysicalBackupsComponent = ({const { formatNumber, formatRelativeTime } = useLocale();const { message } = App.useApp();- const [isBackupsLoading, setIsBackupsLoading] = useState(false);- const [backups, setBackups] = useState<PhysicalBackupListItem[]>([]);const [totalUsageMb, setTotalUsageMb] = useState(0);- const [totalBackups, setTotalBackups] = useState(0);- const [currentLimit, setCurrentLimit] = useState(BACKUPS_PAGE_SIZE);- const [isLoadingMore, setIsLoadingMore] = useState(false);- const [hasMore, setHasMore] = useState(true);-const [backupConfig, setBackupConfig] = useState<PhysicalBackupConfig | undefined>();const [isBackupConfigLoading, setIsBackupConfigLoading] = useState(false);@@ -157,77 +126,22 @@ export const PhysicalBackupsComponent = ({{},);- const lastRequestTimeRef = useRef<number>(0);- const isBackupsRequestInFlightRef = useRef(false);-const isIncrementalAllowed =database.postgresqlPhysical?.backupType !== PhysicalDatabaseBackupType.FULL;- const loadBackups = async (limit?: number, filtersOverride?: PhysicalBackupsFilters) => {- if (isBackupsRequestInFlightRef.current) return;- isBackupsRequestInFlightRef.current = true;-- const requestTime = Date.now();- lastRequestTimeRef.current = requestTime;-- const loadLimit = limit ?? currentLimit;- const activeFilters = filtersOverride ?? filters;-- try {- const response = await physicalBackupsApi.getPhysicalBackups(- database.id,- loadLimit,- 0,- activeFilters,- );-- if (lastRequestTimeRef.current !== requestTime) return;-- setBackups(response.backups);- setTotalUsageMb(response.totalUsageMb);- setTotalBackups(response.total);- setHasMore(response.backups.length < response.total);- } catch (e) {- if (lastRequestTimeRef.current === requestTime) {- alert(translateApiError(e, t));- }- } finally {- isBackupsRequestInFlightRef.current = false;- }- };-- const loadMoreBackups = async () => {- if (isLoadingMore || !hasMore) return;-- setIsLoadingMore(true);-- const newLimit = currentLimit + BACKUPS_PAGE_SIZE;- setCurrentLimit(newLimit);-- const requestTime = Date.now();- lastRequestTimeRef.current = requestTime;-- try {- const response = await physicalBackupsApi.getPhysicalBackups(- database.id,- newLimit,- 0,- filters,- );-- if (lastRequestTimeRef.current !== requestTime) return;+ const fetchBackupsPage = async (cursor: string | undefined) => {+ const response = await physicalBackupsApi.getPhysicalBackups(+ database.id,+ BACKUPS_PAGE_SIZE,+ cursor,+ filters,+ );- setBackups(response.backups);+ if (cursor === undefined) {setTotalUsageMb(response.totalUsageMb);- setTotalBackups(response.total);- setHasMore(response.backups.length < response.total);- } catch (e) {- if (lastRequestTimeRef.current === requestTime) {- alert(translateApiError(e, t));- }}- setIsLoadingMore(false);+ return { items: response.backups, nextCursor: response.nextCursor };};const triggerBackup = async (type: TriggerPhysicalBackupType) => {@@ -236,9 +150,7 @@ export const PhysicalBackupsComponent = ({try {await physicalBackupsApi.triggerPhysicalBackup(database.id, type);await new Promise((resolve) => setTimeout(resolve, 1000));- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);- await loadBackups(BACKUPS_PAGE_SIZE);+ await reloadBackups();} catch (e) {message.error(translateApiError(e, t));}@@ -251,7 +163,7 @@ export const PhysicalBackupsComponent = ({try {await physicalBackupsApi.cancelPhysicalBackup(backupId);- await loadBackups();+ await refreshBackups();} catch (e) {alert(translateApiError(e, t));}@@ -268,9 +180,7 @@ export const PhysicalBackupsComponent = ({try {await physicalBackupsApi.deletePhysicalBackup(backupId);- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);- await loadBackups(BACKUPS_PAGE_SIZE);+ await reloadBackups();} catch (e) {alert(translateApiError(e, t));}@@ -278,56 +188,34 @@ export const PhysicalBackupsComponent = ({setDeletingBackupId(undefined);};+ const {+ items: backups,+ isLoading: isBackupsLoading,+ isLoadingMore,+ hasMore,+ reload: reloadBackups,+ refreshFirstPage: refreshBackups,+ } = usePolledPagedList({+ fetchPage: fetchBackupsPage,+ getItemKey: (backup: PhysicalBackupListItem) => backup.id,+ refreshIntervalMs: BACKUPS_REFRESH_MS,+ scrollContainerRef,+ resetKey: JSON.stringify([database.id, filters]),+ onError: (e) => alert(translateApiError(e, t)),+ });+useEffect(() => {setIsBackupConfigLoading(true);- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);physicalBackupConfigApi.getPhysicalBackupConfigByDbId(database.id).then((config) => {setBackupConfig(config);setIsBackupConfigLoading(false);-- setIsBackupsLoading(true);- loadBackups(BACKUPS_PAGE_SIZE).then(() => setIsBackupsLoading(false));});}, [database]);- useEffect(() => {- setCurrentLimit(BACKUPS_PAGE_SIZE);- setHasMore(true);- setIsBackupsLoading(true);- loadBackups(BACKUPS_PAGE_SIZE, filters).then(() => setIsBackupsLoading(false));- }, [filters]);-- useEffect(() => {- const intervalId = setInterval(() => {- loadBackups();- }, 1_000);-- return () => clearInterval(intervalId);- }, [currentLimit, filters]);-- useEffect(() => {- if (!scrollContainerRef?.current) return;-- const handleScroll = () => {- if (!scrollContainerRef.current) return;-- const { scrollTop, scrollHeight, clientHeight } = scrollContainerRef.current;-- if (scrollHeight - scrollTop <= clientHeight + 100 && hasMore && !isLoadingMore) {- loadMoreBackups();- }- };-- const container = scrollContainerRef.current;- container.addEventListener('scroll', handleScroll);- return () => container.removeEventListener('scroll', handleScroll);- }, [hasMore, isLoadingMore, currentLimit, scrollContainerRef]);-const renderActions = (record: PhysicalBackupListItem): JSX.Element => (<div className="flex gap-2 text-lg">- {/* WAL segments have no standalone backup identity - they are not restored or deleted on their own (use point-in-time restore instead). */}+ {/* WAL ranges have no standalone backup identity - they are not restored or deleted on their own (use point-in-time restore instead). */}{record.type === PhysicalBackupType.WAL ? null : (<>{record.status === PhysicalBackupStatus.IN_PROGRESS && isCanManageDBs && (@@ -394,12 +282,34 @@ export const PhysicalBackupsComponent = ({return '-';};+ const renderCreatedAt = (backup: PhysicalBackupListItem): JSX.Element => {+ const isWalRange = backup.type === PhysicalBackupType.WAL && backup.completedAt !== undefined;+ const latestAt = isWalRange ? backup.completedAt : backup.createdAt;++ return (+ <div>+ {dayjs.utc(backup.createdAt).local().format(getUserTimeFormat().format)}+ {isWalRange && (+ <div className="flex items-center gap-1">+ <ArrowRightOutlined className="text-[10px]" />+ {dayjs.utc(latestAt).local().format(getUserTimeFormat().format)}+ </div>+ )}+ <div className="text-gray-500 dark:text-gray-400">+ ({formatRelativeTime(dayjs.utc(latestAt).local())})+ </div>+ </div>+ );+ };+const columns: ColumnsType<PhysicalBackupListItem> = [{title: t('common.fields.type'),dataIndex: 'type',key: 'type',- render: (type: PhysicalBackupType) => renderTypeBadge(type, t),+ render: (_type: PhysicalBackupType, record: PhysicalBackupListItem) => (+ <PhysicalBackupTypeCellComponent backup={record} />+ ),},{title: t('common.fields.status'),@@ -425,17 +335,7 @@ export const PhysicalBackupsComponent = ({title: t('backups.list.columns.created'),dataIndex: 'createdAt',key: 'createdAt',- render: (createdAt: Date) => (- <div>- {dayjs.utc(createdAt).local().format(getUserTimeFormat().format)}- <br />- <span className="text-gray-500 dark:text-gray-400">- ({formatRelativeTime(dayjs.utc(createdAt).local())})- </span>- </div>- ),- sorter: (a, b) => dayjs(a.createdAt).unix() - dayjs(b.createdAt).unix(),- defaultSortOrder: 'descend',+ render: (_createdAt: Date, record: PhysicalBackupListItem) => renderCreatedAt(record),},{title: t('backups.list.columns.actions'),@@ -545,12 +445,7 @@ export const PhysicalBackupsComponent = ({<div className="text-xs text-gray-500 dark:text-gray-400">{t('backups.list.columns.created')}</div>- <div className="text-sm font-medium">- {dayjs.utc(backup.createdAt).local().format(getUserTimeFormat().format)}- </div>- <div className="text-xs text-gray-500 dark:text-gray-400">- ({formatRelativeTime(dayjs.utc(backup.createdAt).local())})- </div>+ <div className="text-sm font-medium">{renderCreatedAt(backup)}</div></div><div>{renderStatusBadge(backup, setShowingBackupError, t)}</div></div>@@ -560,7 +455,9 @@ export const PhysicalBackupsComponent = ({<div className="text-xs text-gray-500 dark:text-gray-400">{t('common.fields.type')}</div>- <div className="text-sm font-medium">{renderTypeBadge(backup.type, t)}</div>+ <div className="text-sm font-medium">+ <PhysicalBackupTypeCellComponent backup={backup} />+ </div></div><div><div className="text-xs text-gray-500 dark:text-gray-400">@@ -594,7 +491,7 @@ export const PhysicalBackupsComponent = ({)}{!hasMore && backups.length > 0 && (<div className="mt-3 text-center text-sm text-gray-500 dark:text-gray-400">- {t('backups.list.allLoaded', { count: totalBackups })}+ {t('backups.list.allLoaded', { count: backups.length })}</div>)}{!isBackupsLoading && backups.length === 0 && (@@ -622,7 +519,7 @@ export const PhysicalBackupsComponent = ({)}{!hasMore && backups.length > 0 && (<div className="mt-2 text-center text-gray-500 dark:text-gray-400">- {t('backups.list.allLoaded', { count: totalBackups })}+ {t('backups.list.allLoaded', { count: backups.length })}</div>)}</div>diff --git a/frontend/src/features/verification/runs/ui/VerificationsComponent.tsx b/frontend/src/features/verification/runs/ui/VerificationsComponent.tsxindex 87de3277..444f5eb4 100644--- a/frontend/src/features/verification/runs/ui/VerificationsComponent.tsx+++ b/frontend/src/features/verification/runs/ui/VerificationsComponent.tsx@@ -11,7 +11,7 @@ import { Spin, Table, Tag, Tooltip } from 'antd';import type { ColumnsType } from 'antd/es/table';import dayjs from 'dayjs';import type { TFunction } from 'i18next';-import { useEffect, useRef, useState } from 'react';+import { useEffect, useState } from 'react';import { Trans, useTranslation } from 'react-i18next';import type { Database } from '../../../../entity/databases';@@ -24,6 +24,7 @@ import {VerificationTrigger,verificationRunsApi,} from '../../../../entity/verification/runs';+import { usePolledPagedList } from '../../../../shared/hooks';import { getWebsitePageUrl, translateApiError, useLocale } from '../../../../shared/i18n';import { getUserTimeFormat } from '../../../../shared/time';import { VerificationDetailDrawer } from './VerificationDetailDrawer';@@ -133,52 +134,24 @@ export const VerificationsComponent = ({}: Props) => {const { t } = useTranslation();const { locale, formatRelativeTime } = useLocale();- const [verifications, setVerifications] = useState<RestoreVerification[]>([]);- const [isLoading, setIsLoading] = useState(true);const [selectedVerificationId, setSelectedVerificationId] = useState<string | undefined>();const [hasAgents, setHasAgents] = useState<boolean | undefined>();const [cancellingVerificationId, setCancellingVerificationId] = useState<string | undefined>();- const [totalVerifications, setTotalVerifications] = useState(0);- const [currentLimit, setCurrentLimit] = useState(VERIFICATIONS_PAGE_SIZE);- const [isLoadingMore, setIsLoadingMore] = useState(false);- const [hasMore, setHasMore] = useState(true);-- const isVerificationsRequestInFlightRef = useRef(false);-- const loadVerifications = async (limit?: number) => {- if (isVerificationsRequestInFlightRef.current) {- return;- }-- isVerificationsRequestInFlightRef.current = true;- const loadLimit = limit ?? currentLimit;-- try {- const response = await verificationRunsApi.listByDatabase(database.id, loadLimit, 0);- setVerifications(response.verifications);- setTotalVerifications(response.total);- setHasMore(response.verifications.length < response.total);- } catch (e) {- alert(translateApiError(e, t));- } finally {- isVerificationsRequestInFlightRef.current = false;- }- };-- const loadMoreVerifications = async () => {- if (isLoadingMore || !hasMore) {- return;- }-- setIsLoadingMore(true);-- const newLimit = currentLimit + VERIFICATIONS_PAGE_SIZE;- setCurrentLimit(newLimit);+ const fetchVerificationsPage = async (offset: number | undefined) => {+ const pageOffset = offset ?? 0;+ const response = await verificationRunsApi.listByDatabase(+ database.id,+ VERIFICATIONS_PAGE_SIZE,+ pageOffset,+ );- await loadVerifications(newLimit);+ const loadedCount = pageOffset + response.verifications.length;- setIsLoadingMore(false);+ return {+ items: response.verifications,+ nextCursor: loadedCount < response.total ? loadedCount : undefined,+ };};const cancelVerification = async (id: string) => {@@ -186,7 +159,7 @@ export const VerificationsComponent = ({try {await verificationRunsApi.cancel(id);- await loadVerifications();+ await refreshVerifications();} catch (e) {alert(translateApiError(e, t));} finally {@@ -246,20 +219,20 @@ export const VerificationsComponent = ({return <span className="text-xs text-gray-400">-</span>;};- useEffect(() => {- setCurrentLimit(VERIFICATIONS_PAGE_SIZE);- setHasMore(true);- setIsLoading(true);- loadVerifications(VERIFICATIONS_PAGE_SIZE).then(() => setIsLoading(false));- }, [database.id]);-- useEffect(() => {- const intervalId = setInterval(() => {- loadVerifications();- }, VERIFICATIONS_REFRESH_MS);-- return () => clearInterval(intervalId);- }, [currentLimit]);+ const {+ items: verifications,+ isLoading,+ isLoadingMore,+ hasMore,+ refreshFirstPage: refreshVerifications,+ } = usePolledPagedList({+ fetchPage: fetchVerificationsPage,+ getItemKey: (verification: RestoreVerification) => verification.id,+ refreshIntervalMs: VERIFICATIONS_REFRESH_MS,+ scrollContainerRef,+ resetKey: database.id,+ onError: (e) => alert(translateApiError(e, t)),+ });useEffect(() => {let isCancelled = false;@@ -286,26 +259,6 @@ export const VerificationsComponent = ({};}, []);- useEffect(() => {- if (!scrollContainerRef?.current) {- return;- }-- const handleScroll = () => {- if (!scrollContainerRef.current) return;-- const { scrollTop, scrollHeight, clientHeight } = scrollContainerRef.current;-- if (scrollHeight - scrollTop <= clientHeight + 100 && hasMore && !isLoadingMore) {- loadMoreVerifications();- }- };-- const container = scrollContainerRef.current;- container.addEventListener('scroll', handleScroll);- return () => container.removeEventListener('scroll', handleScroll);- }, [hasMore, isLoadingMore, currentLimit, scrollContainerRef]);-const columns: ColumnsType<RestoreVerification> = [{title: t('verification.runs.fields.createdAt'),@@ -430,7 +383,7 @@ export const VerificationsComponent = ({)}{!hasMore && verifications.length > 0 && (<div className="mt-2 text-center text-gray-500 dark:text-gray-400">- {t('verification.runs.allLoaded', { total: totalVerifications })}+ {t('verification.runs.allLoaded', { total: verifications.length })}</div>)}</div>@@ -501,7 +454,7 @@ export const VerificationsComponent = ({)}{!hasMore && verifications.length > 0 && (<div className="mt-3 text-center text-sm text-gray-500 dark:text-gray-400">- {t('verification.runs.allLoaded', { total: totalVerifications })}+ {t('verification.runs.allLoaded', { total: verifications.length })}</div>)}</div>diff --git a/frontend/src/shared/hooks/index.ts b/frontend/src/shared/hooks/index.tsindex 682e1e2b..6648cc16 100644--- a/frontend/src/shared/hooks/index.ts+++ b/frontend/src/shared/hooks/index.ts@@ -3,3 +3,4 @@ export { useIsMobile } from './useIsMobile';export { useIsNewGitHubVersionAvailable } from './useIsNewGitHubVersionAvailable';export { useTemporaryVisibility } from './useTemporaryVisibility';export { usePersistentState } from './usePersistentState';+export { usePolledPagedList } from './usePolledPagedList';diff --git a/frontend/src/shared/hooks/usePolledPagedList.ts b/frontend/src/shared/hooks/usePolledPagedList.tsnew file mode 100644index 00000000..65e30254--- /dev/null+++ b/frontend/src/shared/hooks/usePolledPagedList.ts@@ -0,0 +1,74 @@+import { type RefObject, useEffect, useState } from 'react';++import {+ PagedListController,+ type PagedListOptions,+ type PagedListState,+ createInitialPagedListState,+} from '../lib/PagedListController';++const SCROLL_LOAD_THRESHOLD_PX = 100;++interface Params<TItem, TCursor> extends PagedListOptions<TItem, TCursor> {+ refreshIntervalMs: number;+ scrollContainerRef?: RefObject<HTMLDivElement | null>;+ // A change discards the loaded rows and loads the first page again.+ resetKey: string;+}++// Pages a newest-first list as the user scrolls and keeps it current: each tick+// re-requests only the first page and merges it into the loaded rows.+export function usePolledPagedList<TItem, TCursor>({+ fetchPage,+ getItemKey,+ onError,+ refreshIntervalMs,+ scrollContainerRef,+ resetKey,+}: Params<TItem, TCursor>) {+ const [state, setState] = useState<PagedListState<TItem, TCursor>>(createInitialPagedListState);+ const [controller] = useState(+ () => new PagedListController<TItem, TCursor>({ fetchPage, getItemKey, onError }, setState),+ );++ // The interval and the scroll listener outlive a render, so the controller+ // reads the latest callbacks. Declared first so it runs before the reload.+ useEffect(() => {+ controller.setOptions({ fetchPage, getItemKey, onError });+ });++ useEffect(() => {+ controller.reload();+ }, [resetKey]);++ useEffect(() => {+ const intervalId = setInterval(() => controller.refreshFirstPage(), refreshIntervalMs);++ return () => clearInterval(intervalId);+ }, [refreshIntervalMs]);++ useEffect(() => {+ const container = scrollContainerRef?.current;+ if (!container) return;++ const handleScroll = () => {+ const { scrollTop, scrollHeight, clientHeight } = container;++ if (scrollHeight - scrollTop <= clientHeight + SCROLL_LOAD_THRESHOLD_PX) {+ controller.loadNextPage();+ }+ };++ container.addEventListener('scroll', handleScroll);+ return () => container.removeEventListener('scroll', handleScroll);+ }, [scrollContainerRef]);++ return {+ items: state.list.items,+ isLoading: state.isLoading,+ isLoadingMore: state.isLoadingMore,+ hasMore: state.list.nextCursor !== undefined,+ reload: () => controller.reload(),+ refreshFirstPage: () => controller.refreshFirstPage(),+ };+}diff --git a/frontend/src/shared/i18n/locales/en.ts b/frontend/src/shared/i18n/locales/en.tsindex 7a361e48..e70d2030 100644--- a/frontend/src/shared/i18n/locales/en.ts+++ b/frontend/src/shared/i18n/locales/en.ts@@ -1526,6 +1526,12 @@ export const en = {restore: 'Restore',restoreFromThisBackup: 'Restore from this backup',pointInTimeRestoreTitle: 'Point-in-time restore',+ walRange: {+ segments: 'Segments: {{count}}',+ gapBefore: 'Gap before this range',+ gapBeforeTooltip:+ 'WAL segments are missing between this range and the previous one. Point-in-time restore cannot replay across the gap.',+ },deleteFullConfirmation:'Deleting this full backup removes its entire chain (all incrementals that depend on it). This cannot be undone. Continue?',deleteIncrementalConfirmation:diff --git a/frontend/src/shared/i18n/locales/es.ts b/frontend/src/shared/i18n/locales/es.tsindex 495ef269..cd86da28 100644--- a/frontend/src/shared/i18n/locales/es.ts+++ b/frontend/src/shared/i18n/locales/es.ts@@ -1554,6 +1554,12 @@ export const es: typeof en = {restore: 'Restaurar',restoreFromThisBackup: 'Restaurar desde esta copia',pointInTimeRestoreTitle: 'Restauración a un punto en el tiempo',+ walRange: {+ segments: 'Segmentos: {{count}}',+ gapBefore: 'Hueco antes de este rango',+ gapBeforeTooltip:+ 'Faltan segmentos WAL entre este rango y el anterior. La restauración a un punto en el tiempo no puede pasar por encima del hueco.',+ },deleteFullConfirmation:'Al eliminar esta copia completa se elimina toda su cadena (todas las incrementales que dependen de ella). Esta acción no se puede deshacer. ¿Continuar?',deleteIncrementalConfirmation:diff --git a/frontend/src/shared/i18n/locales/fr.ts b/frontend/src/shared/i18n/locales/fr.tsindex e436589f..2647461b 100644--- a/frontend/src/shared/i18n/locales/fr.ts+++ b/frontend/src/shared/i18n/locales/fr.ts@@ -1563,6 +1563,12 @@ export const fr: typeof en = {restore: 'Restaurer',restoreFromThisBackup: 'Restaurer depuis cette sauvegarde',pointInTimeRestoreTitle: 'Restauration à un instant donné',+ walRange: {+ segments: 'Segments : {{count}}',+ gapBefore: 'Trou avant cette plage',+ gapBeforeTooltip:+ 'Des segments WAL manquent entre cette plage et la précédente. La restauration à un instant donné ne peut pas franchir ce trou.',+ },deleteFullConfirmation:'Si vous supprimez cette sauvegarde complète, toute sa chaîne disparaît avec elle (toutes les sauvegardes incrémentales qui en dépendent). Cette action est irréversible. Continuer ?',deleteIncrementalConfirmation:diff --git a/frontend/src/shared/i18n/locales/pt.ts b/frontend/src/shared/i18n/locales/pt.tsindex 6c87cae3..d174ec53 100644--- a/frontend/src/shared/i18n/locales/pt.ts+++ b/frontend/src/shared/i18n/locales/pt.ts@@ -1546,6 +1546,12 @@ export const pt: typeof en = {restore: 'Restaurar',restoreFromThisBackup: 'Restaurar a partir deste backup',pointInTimeRestoreTitle: 'Restauração point-in-time',+ walRange: {+ segments: 'Segmentos: {{count}}',+ gapBefore: 'Lacuna antes deste intervalo',+ gapBeforeTooltip:+ 'Faltam segmentos WAL entre este intervalo e o anterior. A restauração point-in-time não consegue atravessar a lacuna.',+ },deleteFullConfirmation:'Excluir este backup completo remove toda a cadeia dele (todos os incrementais que dependem dele). Esta ação não pode ser desfeita. Continuar?',deleteIncrementalConfirmation:diff --git a/frontend/src/shared/i18n/locales/ru.ts b/frontend/src/shared/i18n/locales/ru.tsindex 6a6fb1e7..85f4cea4 100644--- a/frontend/src/shared/i18n/locales/ru.ts+++ b/frontend/src/shared/i18n/locales/ru.ts@@ -1529,6 +1529,12 @@ export const ru: typeof en = {restore: 'Восстановить',restoreFromThisBackup: 'Восстановить из этого бекапа',pointInTimeRestoreTitle: 'Восстановление на момент времени',+ walRange: {+ segments: 'Сегментов: {{count}}',+ gapBefore: 'Разрыв перед диапазоном',+ gapBeforeTooltip:+ 'Между этим диапазоном и предыдущим не хватает сегментов WAL. Восстановление на момент времени не может пройти через этот разрыв.',+ },deleteFullConfirmation:'Вместе с этим полным бекапом удалится вся его цепочка (все зависящие от него инкрементальные бекапы). Это действие нельзя отменить. Продолжить?',deleteIncrementalConfirmation:diff --git a/frontend/src/shared/i18n/locales/zh.ts b/frontend/src/shared/i18n/locales/zh.tsindex 6893c7b8..0ea6de6a 100644--- a/frontend/src/shared/i18n/locales/zh.ts+++ b/frontend/src/shared/i18n/locales/zh.ts@@ -1469,6 +1469,11 @@ export const zh: typeof en = {restore: '恢复',restoreFromThisBackup: '从此备份恢复',pointInTimeRestoreTitle: '时间点恢复',+ walRange: {+ segments: '段数:{{count}}',+ gapBefore: '此范围前存在缺口',+ gapBeforeTooltip: '此范围与上一个范围之间缺少 WAL 段,时间点恢复无法跨越该缺口。',+ },deleteFullConfirmation:'删除这个全量备份会移除它的整条备份链(所有依赖它的增量备份)。此操作无法撤销。确定继续吗?',deleteIncrementalConfirmation:diff --git a/frontend/src/shared/lib/PagedListController.test.ts b/frontend/src/shared/lib/PagedListController.test.tsnew file mode 100644index 00000000..172f0a56--- /dev/null+++ b/frontend/src/shared/lib/PagedListController.test.ts@@ -0,0 +1,188 @@+import { describe, expect, it, vi } from 'vitest';++import { PagedListController } from './PagedListController';+import type { PagedListPage } from './pagedList';++interface Row {+ id: string;+}++type RowPage = PagedListPage<Row, string>;++const rows = (...ids: string[]): Row[] => ids.map((id) => ({ id }));++const createDeferredPage = () => {+ let resolvePage: (page: RowPage) => void = () => {};+ const promise = new Promise<RowPage>((resolve) => {+ resolvePage = resolve;+ });++ return { promise, resolvePage };+};++const createController = (fetchPage: (cursor: string | undefined) => Promise<RowPage>) => {+ const onError = vi.fn();+ const controller = new PagedListController<Row, string>(+ { fetchPage, getItemKey: (row) => row.id, onError },+ () => {},+ );++ return { controller, onError };+};++const getLoadedIds = (controller: PagedListController<Row, string>) =>+ controller.getState().list.items.map((row) => row.id);++describe('PagedListController', () => {+ it('loads the first page on reload', async () => {+ const fetchPage = vi.fn().mockResolvedValue({ items: rows('a', 'b'), nextCursor: 'after-b' });+ const { controller } = createController(fetchPage);++ await controller.reload();++ expect(fetchPage).toHaveBeenCalledWith(undefined);+ expect(getLoadedIds(controller)).toEqual(['a', 'b']);+ expect(controller.getState().isLoading).toBe(false);+ });++ it('requests the next page with the stored cursor and appends it', async () => {+ const fetchPage = vi+ .fn()+ .mockResolvedValueOnce({ items: rows('a', 'b'), nextCursor: 'after-b' })+ .mockResolvedValueOnce({ items: rows('c'), nextCursor: undefined });+ const { controller } = createController(fetchPage);++ await controller.reload();+ await controller.loadNextPage();++ expect(fetchPage).toHaveBeenLastCalledWith('after-b');+ expect(getLoadedIds(controller)).toEqual(['a', 'b', 'c']);+ expect(controller.getState().list.nextCursor).toBeUndefined();+ });++ it('requests nothing more once the last page is loaded', async () => {+ const fetchPage = vi.fn().mockResolvedValue({ items: rows('a'), nextCursor: undefined });+ const { controller } = createController(fetchPage);++ await controller.reload();+ await controller.loadNextPage();++ expect(fetchPage).toHaveBeenCalledTimes(1);+ });++ it('refreshes with the first page only and keeps the scrolled tail', async () => {+ const fetchPage = vi+ .fn()+ .mockResolvedValueOnce({ items: rows('a', 'b'), nextCursor: 'after-b' })+ .mockResolvedValueOnce({ items: rows('c', 'd'), nextCursor: 'after-d' })+ .mockResolvedValueOnce({ items: rows('new', 'a'), nextCursor: 'after-a' });+ const { controller } = createController(fetchPage);++ await controller.reload();+ await controller.loadNextPage();+ await controller.refreshFirstPage();++ expect(fetchPage).toHaveBeenLastCalledWith(undefined);+ expect(getLoadedIds(controller)).toEqual(['new', 'a', 'b', 'c', 'd']);+ expect(controller.getState().list.nextCursor).toBe('after-d');+ });++ it('skips a refresh while the previous one is in flight', async () => {+ const pendingRefresh = createDeferredPage();+ const fetchPage = vi+ .fn()+ .mockResolvedValueOnce({ items: rows('a'), nextCursor: undefined })+ .mockReturnValueOnce(pendingRefresh.promise);+ const { controller } = createController(fetchPage);++ await controller.reload();+ const firstRefresh = controller.refreshFirstPage();+ await controller.refreshFirstPage();++ pendingRefresh.resolvePage({ items: rows('new', 'a'), nextCursor: undefined });+ await firstRefresh;++ expect(fetchPage).toHaveBeenCalledTimes(2);+ expect(getLoadedIds(controller)).toEqual(['new', 'a']);+ });++ it('skips a next-page request while the previous one is in flight', async () => {+ const pendingNextPage = createDeferredPage();+ const fetchPage = vi+ .fn()+ .mockResolvedValueOnce({ items: rows('a'), nextCursor: 'after-a' })+ .mockReturnValueOnce(pendingNextPage.promise);+ const { controller } = createController(fetchPage);++ await controller.reload();+ const firstLoad = controller.loadNextPage();+ await controller.loadNextPage();++ pendingNextPage.resolvePage({ items: rows('b'), nextCursor: undefined });+ await firstLoad;++ expect(fetchPage).toHaveBeenCalledTimes(2);+ expect(getLoadedIds(controller)).toEqual(['a', 'b']);+ });++ it('drops a refresh that answers after a reload', async () => {+ const staleRefresh = createDeferredPage();+ const fetchPage = vi+ .fn()+ .mockResolvedValueOnce({ items: rows('old'), nextCursor: undefined })+ .mockReturnValueOnce(staleRefresh.promise)+ .mockResolvedValueOnce({ items: rows('filtered'), nextCursor: undefined });+ const { controller } = createController(fetchPage);++ await controller.reload();+ const refresh = controller.refreshFirstPage();+ await controller.reload();++ staleRefresh.resolvePage({ items: rows('old', 'stale'), nextCursor: undefined });+ await refresh;++ expect(getLoadedIds(controller)).toEqual(['filtered']);+ });++ it('drops a next page that answers after a reload', async () => {+ const staleNextPage = createDeferredPage();+ const fetchPage = vi+ .fn()+ .mockResolvedValueOnce({ items: rows('old'), nextCursor: 'after-old' })+ .mockReturnValueOnce(staleNextPage.promise)+ .mockResolvedValueOnce({ items: rows('filtered'), nextCursor: undefined });+ const { controller } = createController(fetchPage);++ await controller.reload();+ const nextPageLoad = controller.loadNextPage();+ await controller.reload();++ staleNextPage.resolvePage({ items: rows('stale'), nextCursor: undefined });+ await nextPageLoad;++ expect(getLoadedIds(controller)).toEqual(['filtered']);+ expect(controller.getState().isLoadingMore).toBe(false);+ });++ it('reports an error from the current list and ignores one from a replaced list', async () => {+ const staleRefresh = createDeferredPage();+ const fetchPage = vi+ .fn()+ .mockResolvedValueOnce({ items: rows('a'), nextCursor: undefined })+ .mockReturnValueOnce(staleRefresh.promise.then(() => Promise.reject(new Error('stale'))))+ .mockResolvedValueOnce({ items: rows('b'), nextCursor: undefined })+ .mockRejectedValueOnce(new Error('current'));+ const { controller, onError } = createController(fetchPage);++ await controller.reload();+ const refresh = controller.refreshFirstPage();+ await controller.reload();++ staleRefresh.resolvePage({ items: [], nextCursor: undefined });+ await refresh;+ await controller.refreshFirstPage();++ expect(onError).toHaveBeenCalledTimes(1);+ expect(onError).toHaveBeenCalledWith(new Error('current'));+ });+});diff --git a/frontend/src/shared/lib/PagedListController.ts b/frontend/src/shared/lib/PagedListController.tsnew file mode 100644index 00000000..55cffcf0--- /dev/null+++ b/frontend/src/shared/lib/PagedListController.ts@@ -0,0 +1,108 @@+import { type PagedListPage, appendNextPage, mergeRefreshedFirstPage } from './pagedList';++export interface PagedListOptions<TItem, TCursor> {+ fetchPage: (cursor: TCursor | undefined) => Promise<PagedListPage<TItem, TCursor>>;+ getItemKey: (item: TItem) => string;+ onError: (error: unknown) => void;+}++export interface PagedListState<TItem, TCursor> {+ list: PagedListPage<TItem, TCursor>;+ isLoading: boolean;+ isLoadingMore: boolean;+}++export const createInitialPagedListState = <TItem, TCursor>(): PagedListState<TItem, TCursor> => ({+ list: { items: [] },+ isLoading: true,+ isLoadingMore: false,+});++// A response that arrives after a reload belongs to the previous list and is+// dropped. The class holds no React state, so the paging rules are testable+// without rendering.+export class PagedListController<TItem, TCursor> {+ private state = createInitialPagedListState<TItem, TCursor>();++ private generation = 0;+ private isRefreshInFlight = false;++ constructor(+ private options: PagedListOptions<TItem, TCursor>,+ private readonly onStateChange: (state: PagedListState<TItem, TCursor>) => void,+ ) {}++ setOptions(options: PagedListOptions<TItem, TCursor>) {+ this.options = options;+ }++ getState(): PagedListState<TItem, TCursor> {+ return this.state;+ }++ async reload() {+ this.generation += 1;+ const generation = this.generation;++ this.updateState({ isLoading: true });++ try {+ const firstPage = await this.options.fetchPage(undefined);+ if (generation !== this.generation) return;++ this.updateState({ list: firstPage, isLoading: false });+ } catch (e) {+ if (generation !== this.generation) return;++ this.updateState({ isLoading: false });+ this.options.onError(e);+ }+ }++ async refreshFirstPage() {+ if (this.isRefreshInFlight) return;+ this.isRefreshInFlight = true;++ const generation = this.generation;++ try {+ const firstPage = await this.options.fetchPage(undefined);+ if (generation !== this.generation) return;++ this.updateState({+ list: mergeRefreshedFirstPage(this.state.list, firstPage, this.options.getItemKey),+ });+ } catch (e) {+ if (generation === this.generation) this.options.onError(e);+ } finally {+ this.isRefreshInFlight = false;+ }+ }++ async loadNextPage() {+ const cursor = this.state.list.nextCursor;+ if (this.state.isLoadingMore || cursor === undefined) return;++ const generation = this.generation;++ this.updateState({ isLoadingMore: true });++ try {+ const nextPage = await this.options.fetchPage(cursor);+ if (generation !== this.generation) return;++ this.updateState({+ list: appendNextPage(this.state.list, nextPage, this.options.getItemKey),+ });+ } catch (e) {+ if (generation === this.generation) this.options.onError(e);+ } finally {+ this.updateState({ isLoadingMore: false });+ }+ }++ private updateState(change: Partial<PagedListState<TItem, TCursor>>) {+ this.state = { ...this.state, ...change };+ this.onStateChange(this.state);+ }+}diff --git a/frontend/src/shared/lib/index.ts b/frontend/src/shared/lib/index.tsindex 7e75b5b3..b30ecfc4 100644--- a/frontend/src/shared/lib/index.ts+++ b/frontend/src/shared/lib/index.ts@@ -1,5 +1,6 @@export { formatDuration } from './formatDuration';export { FormValidator } from './FormValidator';+export { type PagedListPage, appendNextPage, mergeRefreshedFirstPage } from './pagedList';export { NAME_LIST_TOKEN_SEPARATORS, normalizeNameList } from './normalizeNameList';export { StringUtils } from './StringUtils';export { compareVersions, parseGitHubTag } from './version';diff --git a/frontend/src/shared/lib/pagedList.test.ts b/frontend/src/shared/lib/pagedList.test.tsnew file mode 100644index 00000000..b3da5e15--- /dev/null+++ b/frontend/src/shared/lib/pagedList.test.ts@@ -0,0 +1,145 @@+import { describe, expect, it } from 'vitest';++import { type PagedListPage, appendNextPage, mergeRefreshedFirstPage } from './pagedList';++interface Row {+ id: string;+ label: string;+}++const getRowKey = (row: Row) => row.id;++const rows = (...ids: string[]): Row[] => ids.map((id) => ({ id, label: id }));++const ids = (list: PagedListPage<Row, string>) => list.items.map(getRowKey);++const expectNoDuplicateKeys = (list: PagedListPage<Row, string>) => {+ expect(new Set(ids(list)).size).toBe(list.items.length);+};++describe('appendNextPage', () => {+ it('appends the page and takes its cursor', () => {+ const merged = appendNextPage(+ { items: rows('a', 'b'), nextCursor: 'after-b' },+ { items: rows('c', 'd'), nextCursor: 'after-d' },+ getRowKey,+ );++ expect(ids(merged)).toEqual(['a', 'b', 'c', 'd']);+ expect(merged.nextCursor).toBe('after-d');+ });++ it('drops rows the list already holds', () => {+ const merged = appendNextPage(+ { items: rows('new', 'a', 'b'), nextCursor: '2' },+ { items: rows('b', 'c'), nextCursor: undefined },+ getRowKey,+ );++ expect(ids(merged)).toEqual(['new', 'a', 'b', 'c']);+ expect(merged.nextCursor).toBeUndefined();+ expectNoDuplicateKeys(merged);+ });+});++describe('mergeRefreshedFirstPage', () => {+ it('takes the first page when only the first page is loaded', () => {+ const firstPage = { items: [{ id: 'a', label: 'a-completed' }, ...rows('b')], nextCursor: 'b' };++ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'b'), nextCursor: 'after-b' },+ firstPage,+ getRowKey,+ );++ expect(merged).toEqual(firstPage);+ });++ it('keeps a loaded row that a new row pushed off the first page', () => {+ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'b'), nextCursor: 'after-b' },+ { items: rows('new', 'a'), nextCursor: 'after-a' },+ getRowKey,+ );++ expect(ids(merged)).toEqual(['new', 'a', 'b']);+ expect(merged.nextCursor).toBe('after-b');+ });++ it('puts new rows on top and keeps the tail loaded by scrolling', () => {+ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'b', 'c', 'd', 'e'), nextCursor: 'after-e' },+ { items: rows('new', 'a'), nextCursor: 'after-a' },+ getRowKey,+ );++ expect(ids(merged)).toEqual(['new', 'a', 'b', 'c', 'd', 'e']);+ expect(merged.nextCursor).toBe('after-e');+ expectNoDuplicateKeys(merged);+ });++ it('replaces a changed row in place', () => {+ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'b', 'c'), nextCursor: 'after-c' },+ { items: [{ id: 'a', label: 'a-completed' }, ...rows('b')], nextCursor: 'after-b' },+ getRowKey,+ );++ expect(merged.items).toEqual([{ id: 'a', label: 'a-completed' }, ...rows('b', 'c')]);+ });++ it('drops loaded rows that left the first page', () => {+ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'deleted', 'b', 'c'), nextCursor: 'after-c' },+ { items: rows('a', 'b'), nextCursor: 'after-b' },+ getRowKey,+ );++ expect(ids(merged)).toEqual(['a', 'b', 'c']);+ });++ it('falls back to the first page when its last row is not loaded', () => {+ const firstPage = { items: rows('x', 'y'), nextCursor: 'after-y' };++ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'b', 'c'), nextCursor: 'after-c' },+ firstPage,+ getRowKey,+ );++ expect(merged).toEqual(firstPage);+ });++ it('keeps one row when two ranges merge under the older range id', () => {+ const merged = mergeRefreshedFirstPage(+ { items: rows('full', 'newer-range', 'older-range', 'incr', 'oldest'), nextCursor: 'c' },+ { items: rows('full', 'older-range'), nextCursor: 'after-older-range' },+ getRowKey,+ );++ expect(ids(merged)).toEqual(['full', 'older-range', 'incr', 'oldest']);+ expectNoDuplicateKeys(merged);+ });++ it('keeps no rows when the refreshed first page is empty', () => {+ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'b'), nextCursor: 'after-b' },+ { items: [], nextCursor: undefined },+ getRowKey,+ );++ expect(merged.items).toEqual([]);+ expect(merged.nextCursor).toBeUndefined();+ });++ it('takes the first page when it is the whole list', () => {+ const merged = mergeRefreshedFirstPage(+ { items: rows('a', 'b', 'c'), nextCursor: 'after-c' },+ { items: rows('a', 'b'), nextCursor: undefined },+ getRowKey,+ );++ expect(ids(merged)).toEqual(['a', 'b']);+ expect(merged.nextCursor).toBeUndefined();+ });+});diff --git a/frontend/src/shared/lib/pagedList.ts b/frontend/src/shared/lib/pagedList.tsnew file mode 100644index 00000000..a41cb9c9--- /dev/null+++ b/frontend/src/shared/lib/pagedList.ts@@ -0,0 +1,51 @@+export interface PagedListPage<TItem, TCursor> {+ items: TItem[];+ nextCursor?: TCursor;+}++// Rows already held win over the page's copies: an offset page requested after a+// refresh added rows at the top starts early and repeats rows the list shows.+export const appendNextPage = <TItem, TCursor>(+ loadedList: PagedListPage<TItem, TCursor>,+ nextPage: PagedListPage<TItem, TCursor>,+ getItemKey: (item: TItem) => string,+): PagedListPage<TItem, TCursor> => {+ const loadedKeys = new Set(loadedList.items.map(getItemKey));+ const newItems = nextPage.items.filter((item) => !loadedKeys.has(getItemKey(item)));++ return { items: [...loadedList.items, ...newItems], nextCursor: nextPage.nextCursor };+};++// The refreshed first page replaces every loaded row up to its own last row, so+// rows that changed, moved or vanished near the top are corrected, while the+// tail loaded by scrolling stays. When that last row is not among the loaded+// ones, the loaded rows can no longer be lined up with the fresh page, and the+// list falls back to the first page alone.+export const mergeRefreshedFirstPage = <TItem, TCursor>(+ loadedList: PagedListPage<TItem, TCursor>,+ firstPage: PagedListPage<TItem, TCursor>,+ getItemKey: (item: TItem) => string,+): PagedListPage<TItem, TCursor> => {+ const lastFirstPageItem = firstPage.items[firstPage.items.length - 1];+ if (firstPage.nextCursor === undefined || lastFirstPageItem === undefined) {+ return firstPage;+ }++ const lastFirstPageKey = getItemKey(lastFirstPageItem);+ const lastFirstPageIndex = loadedList.items.findIndex(+ (item) => getItemKey(item) === lastFirstPageKey,+ );++ const isLoadedTailEmpty =+ lastFirstPageIndex === -1 || lastFirstPageIndex === loadedList.items.length - 1;+ if (isLoadedTailEmpty) {+ return firstPage;+ }++ const firstPageKeys = new Set(firstPage.items.map(getItemKey));+ const loadedTail = loadedList.items+ .slice(lastFirstPageIndex + 1)+ .filter((item) => !firstPageKeys.has(getItemKey(item)));++ return { items: [...firstPage.items, ...loadedTail], nextCursor: loadedList.nextCursor };+};diff --git a/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/.openspec.yaml b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/.openspec.yamlnew file mode 100644index 00000000..53f62d70--- /dev/null+++ b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/.openspec.yaml@@ -0,0 +1,2 @@+schema: spec-driven+created: 2026-10-10diff --git a/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/design.md b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/design.mdnew file mode 100644index 00000000..59be46c0--- /dev/null+++ b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/design.md@@ -0,0 +1,157 @@+## Context++See proposal.md - Why for the user-visible problem. The current mechanics:++- The physical list component never sends an offset. Scrolling raises `limit` by 50 and re-requests from offset 0 (`frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsx:199-230`). The backend caps `limit` at 1000 (`backend/internal/features/backups/backups/services/physical_service.go:615-629`), so the list stops growing at 1000 rows while `hasMore` stays true.+- The same component re-requests every loaded row once a second (`PhysicalBackupsComponent.tsx:302-309`). `LogicalBackupsComponent.tsx:317-322` and `VerificationsComponent.tsx:256-262` copy the pattern. Their backends have no cap (`logical_service.go:156`, `verification/runs/service.go:197`), so they keep working but re-send a list that grows with every scroll.+- The physical list is one SQL query over a UNION of the FULL, incremental and committed WAL tables, ordered by `created_at DESC, id DESC` and paged with `LIMIT/OFFSET` (`backend/internal/features/backups/backups/core/physical/service/service.go:474-536`). `CountBackups` runs a second full pass over the same UNION for `total` (`service.go:542-558`).+- A WAL row's `created_at` is the segment's `received_at`. That value is set when the segment is claimed, not when its upload commits (`backend/internal/features/backups/backups/usecases/physical/postgresql/wal_upload.go:105,151`). Concurrent uploads can therefore order segments by time differently from their LSN order.+- `physical_wal_segments` has a unique index on `(database_id, timeline_id, start_lsn)` and an index on `(database_id, received_at)` (`backend/migrations/20260523120000_add_physical_pg_17_backups.sql:289-294`).+- WAL rows already render no actions (`PhysicalBackupsComponent.tsx:331`).+- The backup/restore cycle tests read individual WAL segments through the list API with `type=WAL&limit=1000` (`backend/internal/features/tests/physical/postgresql/shared/helpers.go:452-686`). The same package already reads the WAL catalog directly with `FindByChainSpan` (`shared/sshtunnel.go:131-136`).+- The physical table sorts rows on the client by `createdAt` (`PhysicalBackupsComponent.tsx:437-438`).++Rules this design is constrained by:++- `AGENTS.md`: no unrequested backward compatibility, so the old `offset`/`total` contract is deleted; names state intent.+- `backend/AGENTS.md`: prefer controller tests over unit tests; `features/tests/` only for backup-restore cycles; `time.Now().UTC()`.+- `frontend/AGENTS.md`: FSD import direction and no business logic in `shared/`; one type per model file; no user-facing literals, every locale updated, counts phrased as `Segments: {{count}}`; component section order with hooks below plain functions.++## Goals / Non-Goals++**Goals:**++- Group WAL into ranges in the same SQL query that pages the list, so a page always holds `limit` display rows.+- Make cursor pages stable under inserts at the top.+- One client-side paging, refresh and merge mechanism shared by the three lists.++**Non-Goals:**++- Making the per-request cost independent of the number of WAL segments. The query still reads every committed segment of the database, as `CountBackups` does today.+- Changing the logical backup or restore check APIs.++## Decisions++### D1. Group WAL ranges on the fly in SQL++The list query becomes a chain of CTEs:++```+committed_wal committed segments, plus a per-segment gap flag:+ lag(end_lsn) OVER (PARTITION BY timeline_id ORDER BY start_lsn)+ is_gap_start = prev_end_lsn IS NOT NULL AND prev_end_lsn <> start_lsn+merged FULL + INCREMENTAL + committed_wal rows, as today+filtered merged + the existing outer WHERE (type, status, beforeDate)+grouped in (created_at, id) order, a new group starts at every+ non-WAL row, and at a WAL row whose predecessor in that order+ is non-WAL, is on another timeline, or which is_gap_start+ group_id = running SUM over those starts+items one row per group: non-WAL groups pass through; WAL groups+ aggregate into a range+paged WHERE (sort_time, id) < (cursor) ORDER BY sort_time DESC, id DESC+ LIMIT limit + 1+```++The gap flag is computed over all committed segments before the filter. A before-date filter keeps only older segments, so this does not change any flag a visible segment carries. It also keeps the gap check in LSN order. The time-ordered pass decides only where FULL or INCREMENTAL rows cut a range, so out-of-order `received_at` values cannot split a range by mistake.++A WAL range row projects:++| field | value |+|---|---|+| `id` | id of the range's lowest-LSN segment |+| `startLsn` / `stopLsn` | `MIN(start_lsn)` / `MAX(end_lsn)` |+| `fromWalFilename` / `toWalFilename` | `wal_filename` of the lowest / highest `start_lsn` |+| `walSegmentsCount` | `COUNT(*)` |+| `sizeMb` | `SUM(compressed_size_mb)` |+| `createdAt` / `completedAt` | `MIN(received_at)` / `MAX(received_at)` |+| `hasGapBefore` | `is_gap_start` of the lowest-LSN segment |+| sort time | `MAX(received_at)` |++Using the lowest-LSN segment as `id` keeps a range's identity while it grows at its newest end, which the client merge relies on (D4). Retention deletes the oldest segments, so only the oldest range in the list can change identity, and it sits at the bottom.++Alternatives rejected:++- **A table of ranges maintained on WAL commit.** Reads would cost O(page), but every writer would have to keep it consistent: WAL commit extends or starts a range, retention trims ranges from the old end, orphan cleanup and test deletes split them in the middle. That is much more code on the write path. The on-the-fly query costs the same order as today's `CountBackups`. If the measurement in task 2 shows it too slow, this table is the next step.+- **Grouping in Go over a row stream.** Paging needs the group count before the page boundary is known, so Go would stream rows until `limit + 1` items are built. A long WAL range forces it to read every segment of that range anyway, and the logic splits between SQL and Go.+- **Grouping in the frontend.** A page of 50 rows can be 50 segments of one range, so the client would show one row and still need to page further. The paging bug would return in a new form.+- **Splitting ranges by LSN anchors (a backup's `start_lsn`) instead of list order.** The cut would sit at a recovery-meaningful point, but it would not match what the user sees. A failed FULL, or a filter that hides backups, would leave the visible order and the range boundaries disagreeing.++### D2. Keyset cursor instead of offset for the physical list++The request takes `cursor` and `limit`. The response returns `backups`, `totalUsageMb` and `nextCursor`, which is omitted on the last page. The server fetches `limit + 1` items to know whether a next page exists. The `offset` request parameter, the `total`, `limit` and `offset` response fields, and `CountBackups` are deleted.++The cursor is base64url-encoded JSON of the last item's sort time (RFC 3339 with nanoseconds) and id. It is opaque to the client. The service decodes it and binds both values as query parameters. A cursor that fails to decode returns an error, which the controller already maps to 400 (`backend/internal/features/backups/backups/controllers/physical/controller.go:91-95`). The cursor carries no database id. The database still comes from the path and passes the existing `GetDatabase` permission check before any query runs, so a foreign cursor only sets a position.++Alternatives rejected:++- **Offset over grouped items.** The newest range grows and new backups appear at the top. Offsets shift between requests and pages repeat or skip rows.+- **Explicit `afterTime`/`afterId` query parameters.** They are as safe, but they expose the sort key as API surface and clash in meaning with the existing `beforeDate` filter.+- **Keeping `total`.** Counting grouped items requires a second pass over the whole grouping. The UI needs only `hasMore`, and when everything is loaded the loaded row count is the total.++### D3. Logical backup and restore check lists keep offset paging++Both APIs keep `limit`, `offset` and `total`. The client asks for `offset = number of rows already loaded` and drops rows whose id it already holds. When a refresh has added `k` new rows at the top, the next page starts `k` rows early and repeats those rows. Deduplication removes them. Retention deletes the oldest rows, so it never shifts an offset above the deleted rows. A manual delete reloads the list (D5).++Alternative rejected: **cursor paging for these APIs too.** It would make the three lists uniform, but it would change two more APIs for a case that deduplication already covers.++### D4. One shared hook for paging, refresh and merge++`shared/lib/PagedListController.ts` owns the loaded rows, the next cursor, the loading flags, the in-flight guards and a reset generation counter. It holds no React state, so vitest covers the paging rules in the node environment the project tests run in, without a DOM library. `shared/hooks/usePolledPagedList.ts` wraps it and adds the scroll listener and the refresh interval. Each component passes:++- `fetchPage(cursor)`, returning `{ items, nextCursor? }`. The physical adapter forwards the server cursor. The offset adapters use the offset as the cursor and derive `nextCursor` from `total`.+- `getItemKey(item)`.+- `refreshIntervalMs`, `scrollContainerRef`, and the values whose change resets the list (database id, filters).++The hook returns the rows, `isLoading`, `isLoadingMore`, `hasMore` and `reload()`.++The merge of a refreshed first page (`mergeRefreshedFirstPage`) and the append of a next page with deduplication (`appendNextPage`) are pure functions in `shared/lib/pagedList.ts`, unit-tested with vitest:++```+loaded: [a b c ... x | y z ...] firstPage: [n a' b' ... x']+ ^ last key of firstPage found at index i+result: firstPage ++ loaded[i+1:] without keys already in firstPage+not found, or firstPage is the whole list -> result = firstPage, cursor = its cursor+```++When the first page's last key is found, the stored next cursor stays. When it is not found, the hook falls back to the first page alone and takes its cursor. This handles two rare cases: deletions that empty the loaded prefix, and two ranges merging because a late segment closed a gap. In the second case the merged range keeps the older range's id, so the key is normally found. After a reset, a response with a stale generation is discarded, which replaces the `lastRequestTimeRef` checks in the components.++Both modules are infrastructure with no domain knowledge, so they belong in `shared/`. The three consumers are slices on the same `features` layer and cannot import from each other.++Alternatives rejected:++- **Fixing three copies in place.** The merge logic is the part most likely to be wrong, and three copies would drift.+- **A react-query or SWR infinite query.** It would add a dependency and a caching model the rest of the frontend does not use.++### D5. What triggers a reload versus a refresh++A database switch, a filter change, a trigger and a delete call `reload()`, as they do today. A cancel only refreshes the first page, since the cancelled row stays in place. A delete reloads because a physical FULL delete removes its whole chain, deep below the first page.++### D6. Server order is authoritative in the physical table++The client-side `sorter` and `defaultSortOrder` on the Created column are removed. A range's `createdAt` is its first receive time, while the server places it by its last. A client sort over loaded rows would move ranges and could also reorder a partly loaded list.++### D7. How a range row renders++- Type cell: the WAL badge, then `Segments: {{count}}`, then `fromWalFilename → toWalFilename` in small monospace text. A range with `hasGapBefore` gets an amber "Gap before this range" tag.+- Size, Duration and actions cells: unchanged. Duration already renders `completedAt - createdAt`, the range's time span.+- Created cell: the first and the last receive time, with the relative time of the last one.++New dictionary keys go into every locale under `backups.physical.list.walRange`.++### D8. Cycle tests read segments from the catalog++`committedWalSegmentsInOrder` reads segments through `GetWalSegmentRepository().FindByChainSpan(databaseID, timelineID, 0, LSNMax)`, keeps the committed ones and returns them in LSN order, as `getCommittedWalSegmentCount` already does (`shared/sshtunnel.go:131-147`). Its callers switch from list items to the segment model.++Alternative rejected: **a segment-listing API for tests.** It would be a new public endpoint used only by tests, and expanding a range is out of scope.++## Risks / Trade-offs++- [Every list request reads all committed WAL of the database. A database with 1500 segments a day and 30 days of retention holds about 45 000 rows, read once a second per open tab.] → Task 2 measured the query on the PostgreSQL 17 test database with 50 000 contiguous segments on one timeline and 5 FULLs. The first page and a page deep in the list each took about 90 ms as plain queries, and about 125 ms under `EXPLAIN (ANALYZE, BUFFERS)`. The previous list query plus `CountBackups` took about 15 ms on the same data, so the estimate that grouping costs "the same order as `CountBackups`" was wrong by a factor of six. The time goes to CPU in the two window passes and the per-range `ARRAY_AGG ... ORDER BY` sorts. Raising `work_mem` to 32 MB removed the disk spills but did not change the time. The query stays under the 100 ms budget, with little margin, for a request each open tab sends once a second. The user left the call to the implementer, and the change ships this cost: the stored range table from D1 is a separate change, worth planning if databases with much larger WAL catalogs show up.+- [Breaking API change.] → The frontend and the cycle tests are the only consumers and change in the same commit. No shim stays.+- [The merge falls back to the first page in rare cases and drops the loaded tail.] → The user scrolls again. No row is lost or duplicated.+- [Out-of-order `received_at` puts a range's segments in a different time order from their LSN order.] → Range boundaries come from the LSN gap flag and from non-WAL rows, never from the time order of neighboring segments. From/to names and LSNs are taken by LSN, not by time.+- [Offset pages repeat `k` rows after a refresh adds `k` rows.] → Deduplication by key. The cost is a few extra rows per page request.++## Migration Plan++No schema migration. Backend and frontend ship together. Rollback is a revert of the commit.diff --git a/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/proposal.md b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/proposal.mdnew file mode 100644index 00000000..61c8877b--- /dev/null+++ b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/proposal.md@@ -0,0 +1,44 @@+## Why++The physical backup list cannot show anything past its first 1000 rows. The frontend never requests a second page. Each time the user scrolls to the bottom, it re-requests the whole list from the start with a limit raised by 50, and the backend silently caps that limit at 1000. Once the list reaches the cap, the spinner keeps appearing but no new rows arrive.++Databases that stream WAL hit the cap within hours. Every closed 16 MB WAL segment is its own row, and one reported database produces about 1500 rows a day. The FULL and INCREMENTAL backups the user is looking for get pushed past row 1000, so the type filter is the only way to reach them. The same list is also re-requested in full every second, so a user who has scrolled deep makes the server build and send up to 1000 rows per second.++## What Changes++- The physical backup list collapses consecutive WAL segments into one WAL range row. A range shows its first and last segment names, the segment count, the total size and the time span. A new range starts after a gap in the WAL sequence, after a timeline switch, or where a FULL or INCREMENTAL backup sits between segments in the list. A range that follows a gap is marked as such.+- The newest WAL range grows in place on each refresh. Its last segment, segment count, size and end time update without adding rows.+- **BREAKING** The physical backup list API pages with an opaque cursor instead of `limit`/`offset`. The request takes `cursor`, and the response returns `nextCursor` while more rows exist. The `offset` request parameter and the `total`, `limit` and `offset` response fields are deleted. A WAL row in the response now describes a range, and the per-segment `walFilename` field is deleted.+- **BREAKING** The physical backup list no longer returns individual WAL segments. The backup/restore cycle tests that read segments through this API read them from the WAL segment catalog instead.+- The physical, logical and restore check lists load pages by appending the next page to what is already loaded, instead of re-requesting everything from the start.+- On each refresh tick the three lists re-request only their first page and merge it into the loaded rows. The tick interval stays as it is today.+- The paging, refresh and merge logic moves out of the three components into one shared hook.++## Capabilities++### New Capabilities++- `backup-list-paging`: how the physical backup, logical backup and restore check lists load further pages and stay current while the user scrolls.+- `physical-backup-wal-ranges`: how the physical backup list collapses WAL segments into range rows, where a range ends, and how the newest range updates.++### Modified Capabilities++None.++## Out of scope++- Expanding a WAL range into its individual segments, in the UI or the API.+- A "live" or "streaming" badge on the newest WAL range.+- Hiding WAL by default or changing the default type filter.+- Changing the refresh interval of any list.+- Storing WAL ranges in a table. Ranges are computed per request (see design.md).+- Delete, download or restore actions on a WAL range. WAL rows have none today.+- Cursor paging for the logical backup and restore check APIs. They keep `limit`/`offset` and `total`.+- Changes to the 1000-row cap itself.++## Impact++- Backend: the physical backup list query and DTOs (`backend/internal/features/backups/backups/core/physical/service`, `backend/internal/features/backups/backups/services/physical_service.go`, `backend/internal/features/backups/backups/dto/physical`), its controller tests, and the WAL helpers in `backend/internal/features/tests/physical/postgresql/shared/helpers.go`.+- Frontend: `entity/backups/physical` (API client and models), the three list components (`features/backups/physical`, `features/backups/logical`, `features/verification/runs`), a new hook in `shared/hooks`, and new dictionary keys for the WAL range row in every locale.+- API: the physical backup list endpoint changes shape. The frontend is its only consumer outside the test suite.+- Rules this change answers to: `AGENTS.md`, `backend/AGENTS.md`, `frontend/AGENTS.md`.diff --git a/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/specs/backup-list-paging/spec.md b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/specs/backup-list-paging/spec.mdnew file mode 100644index 00000000..70f4550b--- /dev/null+++ b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/specs/backup-list-paging/spec.md@@ -0,0 +1,106 @@+## Purpose++Defines how the physical backup, logical backup and restore check lists load further rows as the user scrolls and how they stay current while open.++## ADDED Requirements++### Requirement: Scrolling appends the next page++The physical backup, logical backup and restore check lists SHALL load the next page of rows when the user scrolls to the bottom and append it below the rows already shown. Every row in the catalog SHALL be reachable by scrolling, regardless of how many rows precede it.++#### Scenario: Physical list longer than 1000 rows++- **WHEN** a database has 1500 physical backup list rows and the user keeps scrolling to the bottom+- **THEN** the list keeps growing until all 1500 rows are shown++#### Scenario: Earlier pages are not requested again++- **WHEN** the user scrolls to the bottom of a list that already shows three pages+- **THEN** the list requests only the fourth page++### Requirement: Loading stops at the end of the list++A list SHALL stop requesting further pages and stop showing the loading indicator once the server reports that no rows remain. It SHALL then show that every row is loaded, together with the number of rows shown.++#### Scenario: Last page reached++- **WHEN** the server returns a page and reports that no further rows exist+- **THEN** scrolling to the bottom sends no further page request and shows no loading indicator+- **AND** the list shows that all rows are loaded++### Requirement: Refresh updates the newest rows without reloading the rest++On each refresh tick, a list SHALL re-request only its first page and merge it into the rows already shown. Rows below the first page SHALL stay as loaded. The refresh interval of each list SHALL stay unchanged.++#### Scenario: New backup appears while the user is scrolled deep++- **WHEN** the user has loaded five pages and a new backup is created+- **THEN** the next refresh shows the new backup at the top+- **AND** the rows from the second to the fifth page are still shown+- **AND** no row is shown twice++#### Scenario: A row in the first page changes++- **WHEN** a backup in the first page moves from in progress to completed+- **THEN** the next refresh shows it as completed in the same position++#### Scenario: Refresh while the user is scrolled deep++- **WHEN** the user has loaded ten pages and a refresh tick fires+- **THEN** the refresh requests a single page++### Requirement: Rows are not duplicated across pages++A list SHALL show each row at most once, even when rows are added at the top between two page requests.++#### Scenario: Backup added between page loads++- **WHEN** the user has loaded one page and a new backup is created before the user scrolls to the bottom+- **THEN** after the second page loads, no row appears twice in the list++### Requirement: Changing context reloads from the first page++A list SHALL discard loaded rows and load its first page again when the user switches to another database, changes a filter, triggers a backup or deletes a backup.++#### Scenario: Filter changed after scrolling++- **WHEN** the user has loaded several pages and then changes the type filter+- **THEN** the list shows only the first page of rows that match the new filter++### Requirement: Physical backup list pages with a continuation cursor++The physical backup list API SHALL return, with each page, a continuation cursor while further rows exist and no cursor on the last page. A request that passes the cursor SHALL return the rows that follow the previous page, with no row repeated or skipped, even when backups or WAL segments were added at the top between the two requests. The API SHALL no longer accept an offset and SHALL no longer report a total row count.++#### Scenario: Following the cursor++- **WHEN** a client requests the first page with a limit of 50 and then requests again with the returned cursor+- **THEN** the second response contains the next rows in the same newest-first order, starting right after the last row of the first page++#### Scenario: New rows between requests++- **WHEN** a new FULL backup is created between the first and the second page request+- **THEN** the second page neither repeats a row from the first page nor skips a row that existed when the first page was served++#### Scenario: Last page++- **WHEN** a client requests the page that contains the oldest row+- **THEN** the response carries no continuation cursor++#### Scenario: Malformed cursor++- **WHEN** a client passes a cursor the server did not issue or cannot decode+- **THEN** the server rejects the request as invalid and returns no rows++### Requirement: A page cursor grants no access++The continuation cursor SHALL carry only a position in the list. Access to a database's backup list SHALL be decided by the same permission check as without a cursor, and a cursor SHALL never cause rows of a database other than the requested one to be returned.++#### Scenario: Cursor from another database++- **WHEN** a user passes a cursor obtained from database A in a list request for database B+- **THEN** the response contains only database B's rows++#### Scenario: Cursor without access++- **WHEN** a user who cannot view database B requests its backup list with any cursor+- **THEN** the request is rejected exactly as it would be without a cursordiff --git a/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/specs/physical-backup-wal-ranges/spec.md b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/specs/physical-backup-wal-ranges/spec.mdnew file mode 100644index 00000000..caa51e01--- /dev/null+++ b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/specs/physical-backup-wal-ranges/spec.md@@ -0,0 +1,105 @@+## Purpose++Defines how the physical backup list shows WAL as range rows instead of one row per segment, where a range ends, and how the newest range updates.++## ADDED Requirements++### Requirement: Consecutive WAL segments appear as one range row++The physical backup list SHALL show consecutive committed WAL segments as a single WAL range row. A range row SHALL show the names of its first and last segments, the number of segments, their total size, the time the first segment was received and the time the last segment was received.++#### Scenario: Continuous WAL after an incremental backup++- **WHEN** 240 contiguous WAL segments on one timeline were received after an incremental backup and before any later FULL or INCREMENTAL backup+- **THEN** the list shows one WAL range row for them+- **AND** that row shows the first and the last segment names, 240 segments, the sum of their sizes and the receive times of the first and the last segment++### Requirement: Where a WAL range ends++A WAL range SHALL end, and the next segment SHALL start a new range, when any of these holds:++- the next segment does not start where the previous segment on the same timeline ended (a gap),+- the next segment is on a different timeline,+- a FULL or INCREMENTAL backup shown in the same list sits between the two segments in the list order.++#### Scenario: Gap in the WAL sequence++- **WHEN** one segment in the middle of a contiguous sequence is missing from the catalog+- **THEN** the list shows two WAL range rows, one on each side of the missing segment++#### Scenario: Timeline switch++- **WHEN** segments continue on a new timeline after a promotion+- **THEN** the segments of the new timeline form a range separate from the segments of the old timeline++#### Scenario: Backup between segments++- **WHEN** a FULL backup was created while WAL kept streaming+- **THEN** the list shows the FULL backup between two WAL range rows++#### Scenario: Backups filtered out++- **WHEN** the user filters the list to WAL only and the WAL around a FULL backup has no gap+- **THEN** the segments on both sides of that backup form one range row++### Requirement: A range that follows a gap is marked++A WAL range row SHALL be marked as following a gap when an older committed segment exists on the same timeline and the range does not start where the newest such segment ended. A range with no older segment on its timeline SHALL NOT be marked.++#### Scenario: Range after a missing segment++- **WHEN** a segment is missing between two ranges on the same timeline+- **THEN** the newer range is marked as following a gap+- **AND** the older range is not marked unless a gap also precedes it++#### Scenario: Oldest retained range++- **WHEN** retention has deleted every segment older than a range+- **THEN** that range is not marked as following a gap++#### Scenario: First range on a new timeline++- **WHEN** a range is the first one on its timeline+- **THEN** it is not marked as following a gap++### Requirement: Filters apply to segments before they are grouped++The physical backup list filters SHALL select WAL segments first, and only the selected segments SHALL be grouped into ranges.++#### Scenario: Before-date filter cuts a range++- **WHEN** the user filters by a date that falls inside a range of contiguous segments+- **THEN** the list shows a range made of the segments received before that date only, with their count and size++#### Scenario: Status filter that excludes WAL++- **WHEN** the user filters by a status that WAL segments never have+- **THEN** the list shows no WAL range rows++### Requirement: The newest range grows in place++When a new segment is committed right after the last segment of the newest range on the same timeline, and no FULL or INCREMENTAL backup was created after that range, the list SHALL update that range on the next refresh instead of adding a row. The range keeps its position and identity, and its last segment name, segment count, total size and last receive time change.++#### Scenario: Segment committed while the list is open++- **WHEN** the list shows the newest range with 240 segments and one more contiguous segment is committed+- **THEN** after the next refresh the same row shows 241 segments, the new last segment name, the larger size and the later end time+- **AND** the number of rows in the list does not change++### Requirement: A range counts as one row for paging++The physical backup list SHALL count each WAL range row as one row toward the page size, however many segments it covers.++#### Scenario: Many segments and one backup++- **WHEN** a database has 1500 contiguous WAL segments received after its only FULL backup and the user opens the list with a page size of 50+- **THEN** the first page shows the WAL range row and the FULL backup++### Requirement: WAL range rows offer no actions++A WAL range row SHALL offer no delete, download, cancel or restore action, as WAL segment rows did not.++#### Scenario: Actions column for a range++- **WHEN** the list shows a WAL range row to a user who can manage the database+- **THEN** the row's actions cell is emptydiff --git a/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/tasks.md b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/tasks.mdnew file mode 100644index 00000000..7f9142f7--- /dev/null+++ b/openspec/changes/archive/2026-10-10-collapse-wal-ranges-and-fix-backup-pagination/tasks.md@@ -0,0 +1,34 @@+## 1. Backend: grouped list with a cursor++- [x] 1.1 Replace `ListBackups` in `core/physical/service/service.go` with the CTE chain from design D1 (gap flag over committed WAL, filter, time-ordered grouping, range aggregation, keyset page of `limit + 1`). Extend `PhysicalBackupListRow` with the range fields and the sort time, and delete `CountBackups`. Verify with `go build ./...` from `backend/`.+- [x] 1.2 Change the physical list DTOs and service per design D2: the request takes `cursor` instead of `offset`; the response carries `backups`, `totalUsageMb` and `nextCursor`; `PhysicalBackupListItem` drops `walFilename` and gains `fromWalFilename`, `toWalFilename`, `walSegmentsCount` and `hasGapBefore`. Add cursor encoding and decoding in the service, and update the controller's swagger annotations. Verify with `go build ./...` and `make swagger`.+- [x] 1.3 Rewrite the paging controller tests in `controllers/physical/controller_test.go` for the cursor: following `nextCursor` returns the next rows; a FULL created between two requests causes no repeat or skip; the last page has no cursor; a malformed cursor returns 400; a cursor from another database returns only the requested database's rows; a user without access is rejected with a cursor. Delete the offset and `total` tests. Verify with `go test ./internal/features/backups/backups/controllers/physical/... -count=1`.+- [x] 1.4 Add controller tests for WAL ranges, one per scenario in `specs/physical-backup-wal-ranges/spec.md`: one range for contiguous segments with correct count, size, from/to names and times; a split and `hasGapBefore` at a missing segment; no gap mark on the oldest range or on a new timeline's first range; a split at a timeline switch; a split around a FULL; one range across a FULL when filtering to WAL; a before-date filter that cuts a range; a status filter that hides all WAL; a range that keeps its id and grows after another contiguous segment is added; a range that counts as one row toward the limit. Use `physical_testing.CreateTestWalSegment` with explicit LSNs and `ReceivedAt`. Verify with `go test ./internal/features/backups/backups/controllers/physical/... -count=1`.+- [x] 1.5 Switch `committedWalSegmentsInOrder` and `streamPostFullSegments` in `features/tests/physical/postgresql/shared/helpers.go` to read committed segments through `GetWalSegmentRepository().FindByChainSpan` (design D8), and update their callers in `shared/bodies.go`. Delete `listBackupsByType` if it has no callers left. Verify with `go vet ./internal/features/tests/...`.+- [x] 1.6 Run `make lint` from `backend/` and fix every finding.++## 2. Backend: query cost check++- [x] 2.1 Insert 50 000 committed segments on one timeline plus a FULL every 10 000 segments for a test database, then run `EXPLAIN (ANALYZE, BUFFERS)` on the first-page query and on a cursor page deep in the list. Record the timings and plan shape under Risks in `design.md`. Compare the result with the 100 ms per-request budget and record in `design.md` whether the change ships the on-the-fly query or needs the stored range table from D1.++## 3. Frontend: shared paging++- [x] 3.1 Add `shared/lib/pagedList.ts` (design D4) with `mergeRefreshedFirstPage` and `appendNextPage`, and `pagedList.test.ts` covering deduplication on append and, for the merge: only the first page loaded; new rows at the top with a deep loaded tail; a changed row in place; the first page's last key missing, which falls back to the first page; two ranges merged under the older range's id; an empty first page; no duplicate keys in any result. Export it from `shared/lib/index.ts`. Verify with `pnpm test`.+- [x] 3.2 Add `shared/hooks/usePolledPagedList.ts` (design D4): loaded rows, next cursor, `isLoading`, `isLoadingMore`, `hasMore`, `reload()`, the scroll listener, the refresh interval with an in-flight guard, deduplication on append, and a reset generation that discards stale responses. Export it from `shared/hooks/index.ts`. Verify with `pnpm lint` and `pnpm build`.+- [x] 3.3 Move the paging rules out of the hook into `shared/lib/PagedListController.ts`, a class with no React state that the hook wraps, and cover it with `PagedListController.test.ts`: reload loads the first page; the next page is requested with the stored cursor and appended; nothing is requested after the last page; a refresh requests only the first page and keeps the scrolled tail; a second refresh or next-page request is skipped while one is in flight; a refresh or next page that answers after a reload is dropped; only errors of the current list are reported. Verify with `pnpm test`.++## 4. Frontend: physical backup list++- [x] 4.1 Update `entity/backups/physical`: `PhysicalBackupListItem` gets the range fields and loses `walFilename`; `GetPhysicalBackupsResponse` gets `nextCursor` and loses `total`, `limit` and `offset`; `getPhysicalBackups` takes a cursor instead of an offset. Verify with `pnpm build`, which reports every consumer still using the old shape.+- [x] 4.2 Move `PhysicalBackupsComponent` onto `usePolledPagedList` with a 1 s refresh. Delete `currentLimit`, `loadMoreBackups`, `lastRequestTimeRef` and the component's own scroll and interval effects. Trigger, delete, filter change and database change call `reload()`; cancel refreshes only the first page (design D5). Remove the client `sorter` and `defaultSortOrder` (design D6). The "all loaded" line shows the number of loaded rows. Verify with `pnpm lint` and `pnpm build`.+- [x] 4.3 Render WAL range rows per design D7 and add the `backups.physical.list.walRange` keys to `en.ts` and every other locale. Verify with `pnpm lint`, `pnpm test` (the dictionary placeholder check) and `pnpm build`.+- [x] 4.4 Move the type cell into `PhysicalBackupTypeCellComponent` and cover its rendering with `PhysicalBackupTypeCellComponent.test.tsx`: a WAL range shows the segment count and its first and last segment names; a range after a gap shows the gap tag and one without does not; a single-segment range shows one name; a backup shows only its type badge. Verify with `pnpm test`.++## 5. Frontend: logical backup and restore check lists++- [x] 5.1 Move `LogicalBackupsComponent` onto `usePolledPagedList` with an offset adapter (design D3) and keep its 1 s refresh. Delete its `currentLimit` paging, `loadMoreBackups` and its own scroll and interval effects. Verify with `pnpm lint` and `pnpm build`.+- [x] 5.2 Move `VerificationsComponent` onto `usePolledPagedList` the same way and keep `VERIFICATIONS_REFRESH_MS`. Leave the agent availability polling as it is. Verify with `pnpm lint` and `pnpm build`.++## 6. Verification++- [x] 6.1 Run `pnpm format`, `pnpm lint`, `pnpm test` and `pnpm build` from `frontend/`, and `make lint` from `backend/`. Fix every failure.diff --git a/openspec/specs/backup-list-paging/spec.md b/openspec/specs/backup-list-paging/spec.mdnew file mode 100644index 00000000..531a9c42--- /dev/null+++ b/openspec/specs/backup-list-paging/spec.md@@ -0,0 +1,108 @@+# Backup List Paging Specification++## Purpose++Defines how the physical backup, logical backup and restore check lists load further rows as the user scrolls and how they stay current while open.++## Requirements++### Requirement: Scrolling appends the next page++The physical backup, logical backup and restore check lists SHALL load the next page of rows when the user scrolls to the bottom and append it below the rows already shown. Every row in the catalog SHALL be reachable by scrolling, regardless of how many rows precede it.++#### Scenario: Physical list longer than 1000 rows++- **WHEN** a database has 1500 physical backup list rows and the user keeps scrolling to the bottom+- **THEN** the list keeps growing until all 1500 rows are shown++#### Scenario: Earlier pages are not requested again++- **WHEN** the user scrolls to the bottom of a list that already shows three pages+- **THEN** the list requests only the fourth page++### Requirement: Loading stops at the end of the list++A list SHALL stop requesting further pages and stop showing the loading indicator once the server reports that no rows remain. It SHALL then show that every row is loaded, together with the number of rows shown.++#### Scenario: Last page reached++- **WHEN** the server returns a page and reports that no further rows exist+- **THEN** scrolling to the bottom sends no further page request and shows no loading indicator+- **AND** the list shows that all rows are loaded++### Requirement: Refresh updates the newest rows without reloading the rest++On each refresh tick, a list SHALL re-request only its first page and merge it into the rows already shown. Rows below the first page SHALL stay as loaded. The refresh interval of each list SHALL stay unchanged.++#### Scenario: New backup appears while the user is scrolled deep++- **WHEN** the user has loaded five pages and a new backup is created+- **THEN** the next refresh shows the new backup at the top+- **AND** the rows from the second to the fifth page are still shown+- **AND** no row is shown twice++#### Scenario: A row in the first page changes++- **WHEN** a backup in the first page moves from in progress to completed+- **THEN** the next refresh shows it as completed in the same position++#### Scenario: Refresh while the user is scrolled deep++- **WHEN** the user has loaded ten pages and a refresh tick fires+- **THEN** the refresh requests a single page++### Requirement: Rows are not duplicated across pages++A list SHALL show each row at most once, even when rows are added at the top between two page requests.++#### Scenario: Backup added between page loads++- **WHEN** the user has loaded one page and a new backup is created before the user scrolls to the bottom+- **THEN** after the second page loads, no row appears twice in the list++### Requirement: Changing context reloads from the first page++A list SHALL discard loaded rows and load its first page again when the user switches to another database, changes a filter, triggers a backup or deletes a backup.++#### Scenario: Filter changed after scrolling++- **WHEN** the user has loaded several pages and then changes the type filter+- **THEN** the list shows only the first page of rows that match the new filter++### Requirement: Physical backup list pages with a continuation cursor++The physical backup list API SHALL return, with each page, a continuation cursor while further rows exist and no cursor on the last page. A request that passes the cursor SHALL return the rows that follow the previous page, with no row repeated or skipped, even when backups or WAL segments were added at the top between the two requests. The API SHALL no longer accept an offset and SHALL no longer report a total row count.++#### Scenario: Following the cursor++- **WHEN** a client requests the first page with a limit of 50 and then requests again with the returned cursor+- **THEN** the second response contains the next rows in the same newest-first order, starting right after the last row of the first page++#### Scenario: New rows between requests++- **WHEN** a new FULL backup is created between the first and the second page request+- **THEN** the second page neither repeats a row from the first page nor skips a row that existed when the first page was served++#### Scenario: Last page++- **WHEN** a client requests the page that contains the oldest row+- **THEN** the response carries no continuation cursor++#### Scenario: Malformed cursor++- **WHEN** a client passes a cursor the server did not issue or cannot decode+- **THEN** the server rejects the request as invalid and returns no rows++### Requirement: A page cursor grants no access++The continuation cursor SHALL carry only a position in the list. Access to a database's backup list SHALL be decided by the same permission check as without a cursor, and a cursor SHALL never cause rows of a database other than the requested one to be returned.++#### Scenario: Cursor from another database++- **WHEN** a user passes a cursor obtained from database A in a list request for database B+- **THEN** the response contains only database B's rows++#### Scenario: Cursor without access++- **WHEN** a user who cannot view database B requests its backup list with any cursor+- **THEN** the request is rejected exactly as it would be without a cursordiff --git a/openspec/specs/physical-backup-wal-ranges/spec.md b/openspec/specs/physical-backup-wal-ranges/spec.mdnew file mode 100644index 00000000..26be9927--- /dev/null+++ b/openspec/specs/physical-backup-wal-ranges/spec.md@@ -0,0 +1,107 @@+# Physical Backup WAL Ranges Specification++## Purpose++Defines how the physical backup list shows WAL as range rows instead of one row per segment, where a range ends, and how the newest range updates.++## Requirements++### Requirement: Consecutive WAL segments appear as one range row++The physical backup list SHALL show consecutive committed WAL segments as a single WAL range row. A range row SHALL show the names of its first and last segments, the number of segments, their total size, the time the first segment was received and the time the last segment was received.++#### Scenario: Continuous WAL after an incremental backup++- **WHEN** 240 contiguous WAL segments on one timeline were received after an incremental backup and before any later FULL or INCREMENTAL backup+- **THEN** the list shows one WAL range row for them+- **AND** that row shows the first and the last segment names, 240 segments, the sum of their sizes and the receive times of the first and the last segment++### Requirement: Where a WAL range ends++A WAL range SHALL end, and the next segment SHALL start a new range, when any of these holds:++- the next segment does not start where the previous segment on the same timeline ended (a gap),+- the next segment is on a different timeline,+- a FULL or INCREMENTAL backup shown in the same list sits between the two segments in the list order.++#### Scenario: Gap in the WAL sequence++- **WHEN** one segment in the middle of a contiguous sequence is missing from the catalog+- **THEN** the list shows two WAL range rows, one on each side of the missing segment++#### Scenario: Timeline switch++- **WHEN** segments continue on a new timeline after a promotion+- **THEN** the segments of the new timeline form a range separate from the segments of the old timeline++#### Scenario: Backup between segments++- **WHEN** a FULL backup was created while WAL kept streaming+- **THEN** the list shows the FULL backup between two WAL range rows++#### Scenario: Backups filtered out++- **WHEN** the user filters the list to WAL only and the WAL around a FULL backup has no gap+- **THEN** the segments on both sides of that backup form one range row++### Requirement: A range that follows a gap is marked++A WAL range row SHALL be marked as following a gap when an older committed segment exists on the same timeline and the range does not start where the newest such segment ended. A range with no older segment on its timeline SHALL NOT be marked.++#### Scenario: Range after a missing segment++- **WHEN** a segment is missing between two ranges on the same timeline+- **THEN** the newer range is marked as following a gap+- **AND** the older range is not marked unless a gap also precedes it++#### Scenario: Oldest retained range++- **WHEN** retention has deleted every segment older than a range+- **THEN** that range is not marked as following a gap++#### Scenario: First range on a new timeline++- **WHEN** a range is the first one on its timeline+- **THEN** it is not marked as following a gap++### Requirement: Filters apply to segments before they are grouped++The physical backup list filters SHALL select WAL segments first, and only the selected segments SHALL be grouped into ranges.++#### Scenario: Before-date filter cuts a range++- **WHEN** the user filters by a date that falls inside a range of contiguous segments+- **THEN** the list shows a range made of the segments received before that date only, with their count and size++#### Scenario: Status filter that excludes WAL++- **WHEN** the user filters by a status that WAL segments never have+- **THEN** the list shows no WAL range rows++### Requirement: The newest range grows in place++When a new segment is committed right after the last segment of the newest range on the same timeline, and no FULL or INCREMENTAL backup was created after that range, the list SHALL update that range on the next refresh instead of adding a row. The range keeps its position and identity, and its last segment name, segment count, total size and last receive time change.++#### Scenario: Segment committed while the list is open++- **WHEN** the list shows the newest range with 240 segments and one more contiguous segment is committed+- **THEN** after the next refresh the same row shows 241 segments, the new last segment name, the larger size and the later end time+- **AND** the number of rows in the list does not change++### Requirement: A range counts as one row for paging++The physical backup list SHALL count each WAL range row as one row toward the page size, however many segments it covers.++#### Scenario: Many segments and one backup++- **WHEN** a database has 1500 contiguous WAL segments received after its only FULL backup and the user opens the list with a page size of 50+- **THEN** the first page shows the WAL range row and the FULL backup++### Requirement: WAL range rows offer no actions++A WAL range row SHALL offer no delete, download, cancel or restore action, as WAL segment rows did not.++#### Scenario: Actions column for a range++- **WHEN** the list shows a WAL range row to a user who can manage the database+- **THEN** the row's actions cell is empty