fix(db): make paginated database reads always require "order" option (#39017)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-08-23 10:18:18 +02:00
committed by GitHub
parent 0bed1232ee
commit 1c16f04bf5
29 changed files with 161 additions and 65 deletions
+1 -1
View File
@@ -245,7 +245,7 @@ func (opts *SearchBadgeOptions) ToConds() builder.Cond {
}
func (opts *SearchBadgeOptions) ToOrders() string {
return opts.OrderBy.String()
return util.IfZero(opts.OrderBy.String(), "id")
}
// SearchBadges returns badges based on the provided SearchBadgeOptions options
+4
View File
@@ -66,6 +66,10 @@ type FindBlockingOptions struct {
BlockeeID int64
}
func (opts *FindBlockingOptions) ToOrders() string {
return "id"
}
func (opts *FindBlockingOptions) ToConds() builder.Cond {
cond := builder.NewCond()
if opts.BlockerID != 0 {
+1 -5
View File
@@ -208,9 +208,5 @@ func (opts FindExternalUserOptions) ToConds() builder.Cond {
}
func (opts FindExternalUserOptions) ToOrders() string {
return opts.OrderBy
}
func IterateExternalLogin(ctx context.Context, opts FindExternalUserOptions, f func(ctx context.Context, u *ExternalLoginUser) error) error {
return db.Iterate(ctx, opts.ToConds(), f)
return util.IfZero(opts.OrderBy, "external_id")
}
+4
View File
@@ -58,6 +58,10 @@ type SearchUserOptions struct {
IncludeReserved bool
}
func (opts *SearchUserOptions) ToOrders() string {
return "id"
}
func (opts *SearchUserOptions) ApplyPublicOnly(publicOnly bool) {
if publicOnly {
opts.Visible = []structs.VisibleType{structs.VisibleTypePublic}