P0-1 (limits.go): Allow()方法改为全程使用写锁保护counters map读写,避免RLock写入时的data race P0-2 (ticket_workflow.go+ticket_handler.go): Assign/Resolve/Close操作先查询ticket存在性和状态,返回明确的CS_TICKET_4001/CS_TKT_4002/CS_TICKET_4092/CS_TICKET_4093错误码,handler根据错误前缀路由HTTP状态码 P1-1 (ticket_store.go): 移除GetStats中3处手动rows.Close(),只保留defer Close()
28 lines
503 B
Go
28 lines
503 B
Go
package memory
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
type DedupStore struct {
|
|
mu sync.Mutex
|
|
items map[string]string
|
|
}
|
|
|
|
func NewDedupStore() *DedupStore {
|
|
return &DedupStore{items: make(map[string]string)}
|
|
}
|
|
|
|
func (s *DedupStore) TryRecord(_ context.Context, channel, messageID, sessionID string) (bool, error) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
key := fmt.Sprintf("%s:%s", channel, messageID)
|
|
if _, ok := s.items[key]; ok {
|
|
return false, nil
|
|
}
|
|
s.items[key] = sessionID
|
|
return true, nil
|
|
}
|