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

fix 服务的配置文件个数与最新上线时间不对 --bug=119120595 #2925

Merged
merged 2 commits 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
1 change: 1 addition & 0 deletions bcs-services/bcs-bscp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/panjf2000/ants/v2 v2.8.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/samber/lo v1.39.0
github.com/sirupsen/logrus v1.9.3
github.com/smartystreets/goconvey v1.8.1
github.com/spf13/cobra v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions bcs-services/bcs-bscp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2u
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down
31 changes: 30 additions & 1 deletion bcs-services/bcs-bscp/pkg/dal/dao/config_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"errors"
"fmt"

"github.com/samber/lo"
"gorm.io/gen/field"
"gorm.io/gorm"

Expand Down Expand Up @@ -414,5 +415,33 @@ func (dao *configItemDao) GetCount(kit *kit.Kit, bizID uint32, appId []uint32) (
return nil, err
}

return configItem, nil
ma := dao.genQ.AppTemplateBinding
qa := dao.genQ.AppTemplateBinding.WithContext(kit.Ctx)
result, err := qa.Select(ma.AppID, ma.TemplateIDs, ma.UpdatedAt).Where(
ma.BizID.Eq(bizID), ma.AppID.In(appId...)).Find()
if err != nil {
return nil, err
}

// 泛型处理
configItemMap := lo.KeyBy(configItem, func(c *table.ListConfigItemCounts) uint32 {
return c.AppId
})

// 累加配置模板计数
for _, r := range result {
appID := r.AppID()
if _, ok := configItemMap[appID]; ok {
configItemMap[appID].Count += uint32(len(r.Spec.TemplateIDs))
} else {
configItemMap[appID] = &table.ListConfigItemCounts{
AppId: appID,
Count: uint32(len(r.Spec.TemplateIDs)),
UpdatedAt: r.Revision.UpdatedAt,
}
}
}

v := lo.Values(configItemMap)
return v, nil
}
Loading