Skip to content

Commit

Permalink
fix: max sql return null (#278)
Browse files Browse the repository at this point in the history
* fix: max sql return null

* fix: BulkUpdateSubjectSystemGroupBySubjectTemplateGroupWithTx

* fix: update default config

* fix: by cr
  • Loading branch information
zhu327 authored Dec 6, 2023
1 parent a932930 commit 52387f3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 25 deletions.
22 changes: 22 additions & 0 deletions build/support-files/templates/#etc#bkiam_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ customQuotas:
max_actions_limit: 1500
max_resource_types_limit: 500
max_instance_selections_limit: 500
- id: bk_paas3
quota:
web:
subject_max_groups_limit: 1000
- id: bk_bcs_app
quota:
web:
subject_max_groups_limit: 500
- id: bk_ci_rbac
quota:
web:
subject_max_groups_limit: 30000
model:
max_actions_limit: 200
- id: bk_monitorv3
quota:
web:
subject_max_groups_limit: 2000
- id: bk_log_search
quota:
web:
subject_max_groups_limit: 1000

logger:
system:
Expand Down
13 changes: 11 additions & 2 deletions pkg/database/dao/subject_template_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,24 @@ func (m *subjectTemplateGroupManager) GetMaxExpiredAtBySubjectGroup(
subjectPK, groupPK int64,
excludeTemplateID int64,
) (int64, error) {
var expiredAt int64
var expiredAt sql.NullInt64
query := `SELECT
MAX(expired_at)
FROM subject_template_group
WHERE subject_pk = ?
AND group_pk = ?
AND template_id != ?`
err := database.SqlxGet(m.DB, &expiredAt, query, subjectPK, groupPK, excludeTemplateID)
return expiredAt, err
if err != nil {
return 0, err
}

if expiredAt.Valid {
return expiredAt.Int64, nil
}

// Handle NULL case, for example, by returning a default value
return 0, nil
}

func (m *subjectTemplateGroupManager) ListPagingTemplateGroupMember(
Expand Down
48 changes: 25 additions & 23 deletions pkg/service/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,18 +646,22 @@ func (l *groupService) BulkUpdateSubjectSystemGroupBySubjectTemplateGroupWithTx(
}

for _, systemID := range systemIDs {
for _, r := range relations {
err := l.addOrUpdateSubjectSystemGroup(tx, r.SubjectPK, systemID, relation.GroupPK, r.ExpiredAt)
if err != nil {
return errorWrapf(
err,
"addOrUpdateSubjectSystemGroup systemID=`%s`, subjectPK=`%d`, groupPK=`%d`, expiredAt=`%d`, fail",
systemID,
r.SubjectPK,
relation.GroupPK,
r.ExpiredAt,
)
}
err := l.addOrUpdateSubjectSystemGroup(
tx,
relation.SubjectPK,
systemID,
relation.GroupPK,
relation.ExpiredAt,
)
if err != nil {
return errorWrapf(
err,
"addOrUpdateSubjectSystemGroup systemID=`%s`, subjectPK=`%d`, groupPK=`%d`, expiredAt=`%d`, fail",
systemID,
relation.SubjectPK,
relation.GroupPK,
relation.ExpiredAt,
)
}
}
}
Expand Down Expand Up @@ -751,17 +755,15 @@ func (l *groupService) BulkDeleteSubjectTemplateGroupWithTx(
}

for _, systemID := range systemIDs {
for _, r := range relations {
err = l.removeSubjectSystemGroup(tx, r.SubjectPK, systemID, relation.GroupPK)
if err != nil {
return errorWrapf(
err,
"removeSubjectSystemGroup systemID=`%s`, subjectPK=`%d`, groupPK=`%d`, fail",
systemID,
r.SubjectPK,
relation.GroupPK,
)
}
err = l.removeSubjectSystemGroup(tx, relation.SubjectPK, systemID, relation.GroupPK)
if err != nil {
return errorWrapf(
err,
"removeSubjectSystemGroup systemID=`%s`, subjectPK=`%d`, groupPK=`%d`, fail",
systemID,
relation.SubjectPK,
relation.GroupPK,
)
}
}
}
Expand Down

0 comments on commit 52387f3

Please sign in to comment.