Skip to content
Open
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
8 changes: 5 additions & 3 deletions signing/app/cla.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ func (s *claService) Update(cmd *CmdToUpdateCLA) error {
return err
}

if err = s.cs.SetPendingCLAForLink(cmd.LinkId, cla.Id); err != nil {
logs.Error("set pending CLA for link failed: %s, err: %v", cmd.LinkId, err)
if !dp.IsCLATypeIndividual(cla.Type) {
if err = s.cs.SetPendingCLAForLink(cmd.LinkId, cla.Id); err != nil {
logs.Error("set pending CLA for link failed: %s, err: %v", cmd.LinkId, err)
}
}

watch.TriggerNotify()
watch.TriggerNotify(cla.Type)

return nil
}
Expand Down
20 changes: 12 additions & 8 deletions signing/watch/notify_corp_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ func NotifyAdminWatchStop() {
}

// TriggerNotify 立即触发一次通知扫描,不等待定时器周期。
// CLA 更新后应调用此函数,确保企业和个人都在最短时间内收到通知
func TriggerNotify() {
// t 指定要触发的 CLA 类型,只触发对应类型的扫描器
func TriggerNotify(t dp.CLAType) {
if notifyAdminWatchInstance == nil {
return
}
select {
case notifyAdminWatchInstance.corpTrigger <- struct{}{}:
default:
if !dp.IsCLATypeIndividual(t) {
select {
case notifyAdminWatchInstance.corpTrigger <- struct{}{}:
default:
}
}
select {
case notifyAdminWatchInstance.individualTrigger <- struct{}{}:
default:
if dp.IsCLATypeIndividual(t) {
select {
case notifyAdminWatchInstance.individualTrigger <- struct{}{}:
default:
}
}
Comment on lines +50 to 61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation evaluates dp.IsCLATypeIndividual(t) twice and lacks a safety check for when t is nil. If t is nil, it would unexpectedly trigger the corporate notification scanner because !dp.IsCLATypeIndividual(t) evaluates to true.

We can simplify this logic using an if-else structure and add a defensive check to ensure t is not nil before proceeding.

	if t == nil {
		return
	}
	if dp.IsCLATypeIndividual(t) {
		select {
		case notifyAdminWatchInstance.individualTrigger <- struct{}{}:
		default:
		}
	} else {
		select {
		case notifyAdminWatchInstance.corpTrigger <- struct{}{}:
		default:
		}
	}

}

Expand Down
Loading