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
#307)

* fix(worker): subject_action_group_resource excess data `deleted group`
  • Loading branch information
nannan00 authored Oct 31, 2024
1 parent 401cb95 commit 087ca00
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.15
1.12.16
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
4 changes: 4 additions & 0 deletions release.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.12.16

- bugfix: fix the issue where relationships that have been deleted were not cleaned up in the subject_action_group_resource table due to incorrect queries on the maximum expiration time for users and groups

# 1.12.15

- add: query subject group details api
Expand Down

0 comments on commit 087ca00

Please sign in to comment.