From ca53703bd61066aedd791c37799366085f66c7dd Mon Sep 17 00:00:00 2001 From: Zaptoss Date: Tue, 24 Sep 2024 13:14:24 +0300 Subject: [PATCH] Fix events opening --- internal/service/handlers/create_event_type.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/service/handlers/create_event_type.go b/internal/service/handlers/create_event_type.go index 3965a2a..ca0c919 100644 --- a/internal/service/handlers/create_event_type.go +++ b/internal/service/handlers/create_event_type.go @@ -68,8 +68,21 @@ func openEvents(r *http.Request, evType models.EventType) error { return fmt.Errorf("select balances: %w", err) } + balancesWithEvent := make(map[string]struct{}) + existedEvents, err := EventsQ(r).FilterByType(evType.Name).Select() + if err != nil { + return fmt.Errorf("failed to select events with type %s: %w", evType.Name, err) + } + + for _, existedEvent := range existedEvents { + balancesWithEvent[existedEvent.Nullifier] = struct{}{} + } + eventsToInsert := make([]data.Event, 0, len(balances)) for _, b := range balances { + if _, ok := balancesWithEvent[b.Nullifier]; ok { + continue + } eventsToInsert = append(eventsToInsert, data.Event{ Nullifier: b.Nullifier, Status: data.EventOpen,