From d4f5677858e21729765580415f657a8d40ed5850 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Wed, 20 Dec 2023 10:39:38 -0800 Subject: [PATCH] internal/iam: sort public_id descending The previous sort would run the risk of missing items which collide on update or create times because of the compound comparison using strictly less than for both the timestamp and the public_id. Sorting both descending avoids thi issue. --- .../schema/migrations/oss/postgres/80/08_iam_updates.up.sql | 6 +++--- internal/iam/repository_role.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/db/schema/migrations/oss/postgres/80/08_iam_updates.up.sql b/internal/db/schema/migrations/oss/postgres/80/08_iam_updates.up.sql index bc34d2caa..4486eb130 100644 --- a/internal/db/schema/migrations/oss/postgres/80/08_iam_updates.up.sql +++ b/internal/db/schema/migrations/oss/postgres/80/08_iam_updates.up.sql @@ -5,10 +5,10 @@ begin; -- Add new indexes for the create time and update time queries. create index iam_role_create_time_public_id_idx - on iam_role (create_time desc, public_id asc); + on iam_role (create_time desc, public_id desc); create index iam_role_update_time_public_id_idx - on iam_role (update_time desc, public_id asc); + on iam_role (update_time desc, public_id desc); analyze iam_role; -commit; \ No newline at end of file +commit; diff --git a/internal/iam/repository_role.go b/internal/iam/repository_role.go index c8a2c60d5..77d08d9a5 100644 --- a/internal/iam/repository_role.go +++ b/internal/iam/repository_role.go @@ -215,7 +215,7 @@ func (r *Repository) listRoles(ctx context.Context, withScopeIds []string, opt . sql.Named("last_item_id", opts.withStartPageAfterItem.GetPublicId()), ) } - dbOpts := []db.Option{db.WithLimit(limit), db.WithOrder("create_time desc, public_id asc")} + dbOpts := []db.Option{db.WithLimit(limit), db.WithOrder("create_time desc, public_id desc")} return r.queryRoles(ctx, whereClause, args, dbOpts...) } @@ -257,7 +257,7 @@ func (r *Repository) listRolesRefresh(ctx context.Context, updatedAfter time.Tim ) } - dbOpts := []db.Option{db.WithLimit(limit), db.WithOrder("update_time desc, public_id asc")} + dbOpts := []db.Option{db.WithLimit(limit), db.WithOrder("update_time desc, public_id desc")} return r.queryRoles(ctx, whereClause, args, dbOpts...) }