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: max sql return null #278

Merged
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
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