From 087ca0098e3e4c03c214b4f085cf710485688fdb Mon Sep 17 00:00:00 2001 From: nannan00 <17491932+nannan00@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:30:47 +0800 Subject: [PATCH] fix(worker): subject_action_group_resource excess data `deleted group` (#307) * fix(worker): subject_action_group_resource excess data `deleted group` --- VERSION | 2 +- pkg/database/dao/subject_template_group.go | 2 ++ pkg/task/handler/handler.go | 8 +++++++- release.md | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 0c86ae8c..c22268b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.12.15 +1.12.16 diff --git a/pkg/database/dao/subject_template_group.go b/pkg/database/dao/subject_template_group.go index 315f9f67..9d1b7803 100644 --- a/pkg/database/dao/subject_template_group.go +++ b/pkg/database/dao/subject_template_group.go @@ -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 } diff --git a/pkg/task/handler/handler.go b/pkg/task/handler/handler.go index d0d14c22..265b2bc3 100644 --- a/pkg/task/handler/handler.go +++ b/pkg/task/handler/handler.go @@ -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( diff --git a/release.md b/release.md index 374d15dd..f2ac45ca 100644 --- a/release.md +++ b/release.md @@ -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