Skip to content

Commit

Permalink
fix(worker): subject_action_group_resource excess data deleted group
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 committed Oct 31, 2024
1 parent 401cb95 commit d3c14db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/database/dao/subject_template_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func (m *subjectTemplateGroupManager) GetMaxExpiredAtBySubjectGroup(
return expiredAt.Int64, nil
}

// FIXME (nan): 使用 Max 聚合 SQL 且对 NULL 返回了 nil, 所以不存在 sql.ErrNoRows 的情况,
// 但上层调用点却使用了 sql.ErrNoRows 判断后进行各种逻辑处理,需要 Review 后决策如何修复
// Handle NULL case, for example, by returning a default value
return 0, nil
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/task/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ func (h *groupAlterMessageHandler) alterSubjectActionGroupResource(subjectPK, ac
subjectPK, groupPK,
)
}
found := !errors.Is(err, service.ErrGroupMemberNotFound)
// Note:
// 由于 groupService.GetMaxExpiredAtBySubjectGroup 函数里的
// subjectTemplateGroupManager.GetMaxExpiredAtBySubjectGroup 使用 Max 聚合 SQL 且对 NULL 返回了 nil
// 所以导致 不可能存在 sql.ErrNoRows 的情况,即 ErrGroupMemberNotFound 也不可能出现
// 临时解决方案:由于 用户与用户组关系存在时 expiredAt 一定不为空,所以这里判断 expiredAt != 0 来表示用户还在用户组里
// FIXME (nan): 待底层 GetMaxExpiredAtBySubjectGroup 修复后,这里也对应进行修复
found := !errors.Is(err, service.ErrGroupMemberNotFound) && expiredAt != 0

// 查询group action授权资源实例
resourceMap, err := cacheimpls.GetGroupActionAuthorizedResource(
Expand Down

0 comments on commit d3c14db

Please sign in to comment.