Skip to content

Commit

Permalink
fixed refreshSettingStatus and refreshLabelStatus function for empty …
Browse files Browse the repository at this point in the history
…data.
  • Loading branch information
zensh committed Jun 5, 2020
1 parent a70e7b7 commit d1b6279
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (m *Model) unlock(ctx context.Context, key string) {
// 比如用户因为属于 n 个群组而被重复设置环境标签
func (m *Model) tryRefreshLabelStatus(ctx context.Context, labelID int64) {
if err := m.refreshLabelStatus(ctx, labelID); err != nil {
logging.Infof("tryRefreshLabelStatus: labelID %d, error %v", labelID, err)
logging.Debugf("tryRefreshLabelStatus: labelID %d, error %v", labelID, err)
}
}
func (m *Model) refreshLabelStatus(ctx context.Context, labelID int64) error {
Expand All @@ -335,7 +335,7 @@ func (m *Model) refreshLabelStatus(ctx context.Context, labelID int64) error {
}

sd = m.DB.Select(
goqu.SUM(goqu.I("t2.status")).As("status")).
goqu.L("IFNULL(SUM(`t2`.`status`), 0)").As("status")).
From(
goqu.T(schema.TableGroupLabel).As("t1"),
goqu.T(schema.TableGroup).As("t2")).
Expand All @@ -355,7 +355,7 @@ func (m *Model) refreshLabelStatus(ctx context.Context, labelID int64) error {
// 比如用户因为属于 n 个群组而被重复设置配置项
func (m *Model) tryRefreshSettingStatus(ctx context.Context, settingID int64) {
if err := m.refreshSettingStatus(ctx, settingID); err != nil {
logging.Infof("tryRefreshSettingStatus: settingID %d, error %v", settingID, err)
logging.Debugf("tryRefreshSettingStatus: settingID %d, error %v", settingID, err)
}
}
func (m *Model) refreshSettingStatus(ctx context.Context, settingID int64) error {
Expand All @@ -372,7 +372,7 @@ func (m *Model) refreshSettingStatus(ctx context.Context, settingID int64) error
}

sd = m.DB.Select(
goqu.SUM(goqu.I("t2.status")).As("status")).
goqu.L("IFNULL(SUM(`t2`.`status`), 0)").As("status")).
From(
goqu.T(schema.TableGroupSetting).As("t1"),
goqu.T(schema.TableGroup).As("t2")).
Expand All @@ -391,7 +391,7 @@ func (m *Model) refreshSettingStatus(ctx context.Context, settingID int64) error
// tryRefreshGroupStatus 更新指定 group 的 Status(成员数量统计)值
func (m *Model) tryRefreshGroupStatus(ctx context.Context, groupID int64) {
if err := m.refreshGroupStatus(ctx, groupID); err != nil {
logging.Infof("tryRefreshGroupStatus: groupID %d, error %v", groupID, err)
logging.Debugf("tryRefreshGroupStatus: groupID %d, error %v", groupID, err)
}
}
func (m *Model) refreshGroupStatus(ctx context.Context, groupID int64) error {
Expand All @@ -414,7 +414,7 @@ func (m *Model) refreshGroupStatus(ctx context.Context, groupID int64) error {
// tryRefreshModuleStatus 更新指定 module 的 Status(功能模块的配置项统计)值
func (m *Model) tryRefreshModuleStatus(ctx context.Context, moduleID int64) {
if err := m.refreshModuleStatus(ctx, moduleID); err != nil {
logging.Infof("tryRefreshModuleStatus: moduleID %d, error %v", moduleID, err)
logging.Debugf("tryRefreshModuleStatus: moduleID %d, error %v", moduleID, err)
}
}
func (m *Model) refreshModuleStatus(ctx context.Context, moduleID int64) error {
Expand All @@ -437,7 +437,7 @@ func (m *Model) refreshModuleStatus(ctx context.Context, moduleID int64) error {
// tryIncreaseStatisticStatus 加减指定 key 的统计值
func (m *Model) tryIncreaseStatisticStatus(ctx context.Context, key schema.StatisticKey, delta int) {
if err := m.increaseStatisticStatus(ctx, key, delta); err != nil {
logging.Infof("tryIncreaseStatisticStatus: key %s, delta: %d, error %v", key, delta, err)
logging.Debugf("tryIncreaseStatisticStatus: key %s, delta: %d, error %v", key, delta, err)
}
}
func (m *Model) increaseStatisticStatus(ctx context.Context, key schema.StatisticKey, delta int) error {
Expand Down Expand Up @@ -478,7 +478,7 @@ func (m *Model) updateStatisticValue(ctx context.Context, key schema.StatisticKe
// tryRefreshUsersTotalSize 更新用户总数
func (m *Model) tryRefreshUsersTotalSize(ctx context.Context) {
if err := m.refreshUsersTotalSize(ctx); err != nil {
logging.Infof("refreshUsersTotalSize: error %v", err)
logging.Debugf("refreshUsersTotalSize: error %v", err)
}
}
func (m *Model) refreshUsersTotalSize(ctx context.Context) error {
Expand All @@ -499,7 +499,7 @@ func (m *Model) refreshUsersTotalSize(ctx context.Context) error {
// tryRefreshGroupsTotalSize 更新群组总数
func (m *Model) tryRefreshGroupsTotalSize(ctx context.Context) {
if err := m.refreshGroupsTotalSize(ctx); err != nil {
logging.Infof("refreshGroupsTotalSize: error %v", err)
logging.Debugf("refreshGroupsTotalSize: error %v", err)
}
}
func (m *Model) refreshGroupsTotalSize(ctx context.Context) error {
Expand All @@ -520,7 +520,7 @@ func (m *Model) refreshGroupsTotalSize(ctx context.Context) error {
// tryRefreshProductsTotalSize 更新产品总数
func (m *Model) tryRefreshProductsTotalSize(ctx context.Context) {
if err := m.refreshProductsTotalSize(ctx); err != nil {
logging.Infof("refreshProductsTotalSize: error %v", err)
logging.Debugf("refreshProductsTotalSize: error %v", err)
}
}
func (m *Model) refreshProductsTotalSize(ctx context.Context) error {
Expand All @@ -541,7 +541,7 @@ func (m *Model) refreshProductsTotalSize(ctx context.Context) error {
// tryRefreshLabelsTotalSize 更新标签总数
func (m *Model) tryRefreshLabelsTotalSize(ctx context.Context) {
if err := m.refreshLabelsTotalSize(ctx); err != nil {
logging.Infof("refreshLabelsTotalSize: error %v", err)
logging.Debugf("refreshLabelsTotalSize: error %v", err)
}
}
func (m *Model) refreshLabelsTotalSize(ctx context.Context) error {
Expand All @@ -562,7 +562,7 @@ func (m *Model) refreshLabelsTotalSize(ctx context.Context) error {
// tryRefreshModulesTotalSize 更新模块总数
func (m *Model) tryRefreshModulesTotalSize(ctx context.Context) {
if err := m.refreshModulesTotalSize(ctx); err != nil {
logging.Infof("refreshModulesTotalSize: error %v", err)
logging.Debugf("refreshModulesTotalSize: error %v", err)
}
}
func (m *Model) refreshModulesTotalSize(ctx context.Context) error {
Expand All @@ -583,7 +583,7 @@ func (m *Model) refreshModulesTotalSize(ctx context.Context) error {
// tryRefreshSettingsTotalSize 更新配置项总数
func (m *Model) tryRefreshSettingsTotalSize(ctx context.Context) {
if err := m.refreshSettingsTotalSize(ctx); err != nil {
logging.Infof("refreshSettingsTotalSize: error %v", err)
logging.Debugf("refreshSettingsTotalSize: error %v", err)
}
}
func (m *Model) refreshSettingsTotalSize(ctx context.Context) error {
Expand All @@ -603,7 +603,7 @@ func (m *Model) refreshSettingsTotalSize(ctx context.Context) error {

func (m *Model) tryIncreaseLabelsStatus(ctx context.Context, labelIDs []int64, delta int) {
if err := m.increaseLabelsStatus(ctx, labelIDs, delta); err != nil {
logging.Infof("increaseLabelsStatus: labelIDs [%v], delta: %d, error %v", labelIDs, delta, err)
logging.Debugf("increaseLabelsStatus: labelIDs [%v], delta: %d, error %v", labelIDs, delta, err)
}
}
func (m *Model) increaseLabelsStatus(ctx context.Context, labelIDs []int64, delta int) error {
Expand All @@ -623,7 +623,7 @@ func (m *Model) increaseLabelsStatus(ctx context.Context, labelIDs []int64, delt

func (m *Model) tryIncreaseSettingsStatus(ctx context.Context, settingIDs []int64, delta int) {
if err := m.increaseSettingsStatus(ctx, settingIDs, delta); err != nil {
logging.Infof("increaseSettingsStatus: settingIDs [%v], delta: %d, error %v", settingIDs, delta, err)
logging.Debugf("increaseSettingsStatus: settingIDs [%v], delta: %d, error %v", settingIDs, delta, err)
}
}
func (m *Model) increaseSettingsStatus(ctx context.Context, settingIDs []int64, delta int) error {
Expand All @@ -643,7 +643,7 @@ func (m *Model) increaseSettingsStatus(ctx context.Context, settingIDs []int64,

func (m *Model) tryIncreaseModulesStatus(ctx context.Context, moduleIDs []int64, delta int) {
if err := m.increaseModulesStatus(ctx, moduleIDs, delta); err != nil {
logging.Infof("increaseModulesStatus: moduleIDs [%v], delta: %d, error %v", moduleIDs, delta, err)
logging.Debugf("increaseModulesStatus: moduleIDs [%v], delta: %d, error %v", moduleIDs, delta, err)
}
}
func (m *Model) increaseModulesStatus(ctx context.Context, moduleIDs []int64, delta int) error {
Expand Down
9 changes: 8 additions & 1 deletion src/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ func (m *User) RefreshLabels(ctx context.Context, id int64, now int64, force boo
if err != nil {
return err
}
defer scanner.Close()

set := make(map[int64]struct{})
for scanner.Next() {
myLabelInfo := schema.MyLabelInfo{}
if err := scanner.ScanStruct(&myLabelInfo); err != nil {
scanner.Close()
return err
}
if _, ok := set[myLabelInfo.ID]; ok {
Expand All @@ -180,6 +180,13 @@ func (m *User) RefreshLabels(ctx context.Context, id int64, now int64, force boo
})
}

if err := scanner.Close(); err != nil {
return err
}
if err := scanner.Err(); err != nil {
return err
}

refreshed = true
user.ActiveAt = time.Now().UTC().Unix()
_ = user.PutLabels(data)
Expand Down

0 comments on commit d1b6279

Please sign in to comment.