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.
This commit is contained in:
Johan Brandhorst-Satzkorn committed 2024-01-05 07:43:21 -08:00
1 parent f9950a7e1c
commit d4f5677858
2 files changed
+5 -5

No files matched your search

@@ -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;
commit;
+2 -2
View File
@@ -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...)
}