Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 除强时间概念的列表外,其它列表一律按名称首字符ASCII排序 #2924

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bcs-services/bcs-bscp/cmd/config-server/service/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (s *Service) ListKvs(ctx context.Context, req *pbcs.ListKvsReq) (*pbcs.List
KvType: req.KvType,
Sort: req.Sort,
Order: req.Order,
TopIds: req.TopIds,
}
if !req.All {
if req.Limit == 0 {
Expand Down Expand Up @@ -198,12 +199,13 @@ func (s *Service) BatchUpsertKvs(ctx context.Context, req *pbcs.BatchUpsertKvsRe
Kvs: kvs,
ReplaceAll: true,
}
if _, err := s.client.DS.BatchUpsertKvs(grpcKit.RpcCtx(), r); err != nil {
data, err := s.client.DS.BatchUpsertKvs(grpcKit.RpcCtx(), r)
if err != nil {
logs.Errorf("batch upsert kv failed, err: %v, rid: %s", err, grpcKit.Rid)
return nil, err
}

return &pbcs.BatchUpsertKvsResp{}, nil
return &pbcs.BatchUpsertKvsResp{Ids: data.Ids}, nil
}

// UnDeleteKv reverses the deletion of a key-value pair by reverting the current kvType and value to the previous
Expand Down
19 changes: 16 additions & 3 deletions bcs-services/bcs-bscp/cmd/data-service/service/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
pbbase "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/core/base"
pbkv "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/core/kv"
pbds "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/data-service"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/tools"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types"
)

Expand Down Expand Up @@ -152,6 +153,7 @@ func (s *Service) ListKvs(ctx context.Context, req *pbds.ListKvsReq) (*pbds.List
Sort: req.Sort,
Order: types.Order(req.Order),
}
topIds, _ := tools.StrToUint32Slice(req.TopIds)
opt := &types.ListKvOption{
BizID: req.BizId,
AppID: req.AppId,
Expand All @@ -160,6 +162,7 @@ func (s *Service) ListKvs(ctx context.Context, req *pbds.ListKvsReq) (*pbds.List
All: req.All,
Page: page,
KvType: req.KvType,
TopIDs: topIds,
}
po := &types.PageOption{
EnableUnlimitedLimit: true,
Expand Down Expand Up @@ -231,7 +234,7 @@ func (s *Service) DeleteKv(ctx context.Context, req *pbds.DeleteKvReq) (*pbbase.
}

// BatchUpsertKvs is used to insert or update key-value data in bulk.
func (s *Service) BatchUpsertKvs(ctx context.Context, req *pbds.BatchUpsertKvsReq) (*pbbase.EmptyResp, error) {
func (s *Service) BatchUpsertKvs(ctx context.Context, req *pbds.BatchUpsertKvsReq) (*pbds.BatchUpsertKvsResp, error) {

kt := kit.FromGrpcContext(ctx)

Expand Down Expand Up @@ -303,8 +306,18 @@ func (s *Service) BatchUpsertKvs(ctx context.Context, req *pbds.BatchUpsertKvsRe
logs.Errorf("commit transaction failed, err: %v, rid: %s", e, kt.Rid)
return nil, e
}

return new(pbbase.EmptyResp), nil
createId := []uint32{}
updateId := []uint32{}
for _, item := range toCreate {
createId = append(createId, item.ID)
}
for _, item := range toUpdate {
updateId = append(updateId, item.ID)
}
mergedID := append(createId, updateId...) // nolint
return &pbds.BatchUpsertKvsResp{
Ids: mergedID,
}, nil
}

func (s *Service) getKv(kt *kit.Kit, bizID, appID, version uint32, key string) (table.DataType, string, error) {
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/pkg/dal/dao/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (dao *credentialDao) List(kit *kit.Kit, bizID uint32, searchKey string, opt

result, count, err := q.Where(m.BizID.Eq(bizID)).
Where(conds...).
Order(m.ID.Desc()).
Order(m.Name).
FindByPage(opt.Offset(), opt.LimitInt())
if err != nil {
return nil, 0, err
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/pkg/dal/dao/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (dao *hookDao) ListWithRefer(kit *kit.Kit, opt *types.ListHooksWithReferOpt
h := dao.genQ.Hook
hr := dao.genQ.HookRevision
rh := dao.genQ.ReleasedHook
q := dao.genQ.Hook.WithContext(kit.Ctx).Where(h.BizID.Eq(opt.BizID)).Order(h.ID.Desc())
q := dao.genQ.Hook.WithContext(kit.Ctx).Where(h.BizID.Eq(opt.BizID)).Order(h.Name)

if opt.Name != "" {
q = q.Where(h.Name.Like(fmt.Sprintf("%%%s%%", opt.Name)))
Expand Down
3 changes: 3 additions & 0 deletions bcs-services/bcs-bscp/pkg/dal/dao/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/criteria/errf"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/gen"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/table"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/utils"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types"
)
Expand Down Expand Up @@ -148,6 +149,8 @@ func (dao *kvDao) List(kit *kit.Kit, opt *types.ListKvOption) ([]*table.Kv, int6
}
if opt.Page.Order == types.Descending {
q = q.Order(orderCol.Desc())
} else if len(opt.TopIDs) != 0 {
q = q.Order(utils.NewCustomExpr("CASE WHEN id IN (?) THEN 0 ELSE 1 END,`key` asc", []interface{}{opt.TopIDs}))
} else {
q = q.Order(orderCol)
}
Expand Down
Loading
Loading