Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
fix: remove duplicate events from nats
Browse files Browse the repository at this point in the history
  • Loading branch information
TroyKomodo committed Feb 20, 2024
1 parent b0496ec commit da0ea04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions data/events/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ func (inst *EventsInst) Dispatch(t EventType, cm ChangeMap, cond ...EventConditi

for _, c := range cond {
// TODO: check if it's necesary to publish for both bools
for _, b := range []bool{false, true} {
err = inst.nc.Publish(inst.subject+"."+CreateDispatchKey(t, c, b), data)
if err != nil {
zap.S().Errorw("nats publish", "error", err)
}
err = inst.nc.Publish(inst.subject+"."+CreateDispatchKey(t, c), data)
if err != nil {
zap.S().Errorw("nats publish", "error", err)
}
}
}
Expand Down Expand Up @@ -124,12 +122,10 @@ func (inst *EventsInst) DispatchWithEffect(t EventType, cm ChangeMap, opt Dispat

if opt.Whisper == "" {
for _, c := range cond {
for _, b := range []bool{false, true} {
payloads[CreateDispatchKey(t, c, b)] = data
}
payloads[CreateDispatchKey(t, c)] = data
}
} else {
payloads[CreateDispatchKey(EventTypeWhisper, EventCondition{"session_id": opt.Whisper}, false)] = data
payloads[CreateDispatchKey(EventTypeWhisper, EventCondition{"session_id": opt.Whisper})] = data
}

go func() {
Expand Down
4 changes: 2 additions & 2 deletions data/events/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ type DispatchPayload struct {
Whisper string `json:"whisper,omitempty"`
}

func CreateDispatchKey(t EventType, condition EventCondition, wildcard bool) string {
func CreateDispatchKey(t EventType, condition EventCondition) string {
s := strings.Builder{}

s.WriteString(OpcodeDispatch.PublishKey())
s.WriteString(".type.")
s.WriteString(utils.Ternary(wildcard, t.ObjectName()+".*", string(t)))
s.WriteString(string(t))

if len(condition) > 0 {
s.WriteString(".")
Expand Down

0 comments on commit da0ea04

Please sign in to comment.