CloudMigrations: Limit frontend query to get latest snapshots (#93639)

* latest param to endpoint and adapt frontend query

* change to sort param

* api

* remove description
This commit is contained in:
Dana Axinte
2024-10-01 09:28:25 +01:00
committed by GitHub
parent 8b6cbae96b
commit 1a31abe254
9 changed files with 90 additions and 12 deletions
@@ -23,9 +23,10 @@ type sqlStore struct {
}
const (
tableName = "cloud_migration_resource"
secretType = "cloudmigration-snapshot-encryption-key"
GetAllSnapshots = -1
tableName = "cloud_migration_resource"
secretType = "cloudmigration-snapshot-encryption-key"
GetAllSnapshots = -1
GetSnapshotListSortingLatest = "latest"
)
func (ss *sqlStore) GetMigrationSessionByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
@@ -278,7 +279,9 @@ func (ss *sqlStore) GetSnapshotList(ctx context.Context, query cloudmigration.Li
offset := (query.Page - 1) * query.Limit
sess.Limit(query.Limit, offset)
}
sess.OrderBy("cloud_migration_snapshot.created DESC")
if query.Sort == GetSnapshotListSortingLatest {
sess.OrderBy("cloud_migration_snapshot.created DESC")
}
return sess.Find(&snapshots, &cloudmigration.CloudMigrationSnapshot{
SessionUID: query.SessionUID,
})