diff --git a/backend/pkg/api/data_access/archiver.go b/backend/pkg/api/data_access/archiver.go index bb28571b94..31462c79dc 100644 --- a/backend/pkg/api/data_access/archiver.go +++ b/backend/pkg/api/data_access/archiver.go @@ -7,6 +7,7 @@ import ( "github.com/doug-martin/goqu/v9" t "github.com/gobitfly/beaconchain/pkg/api/types" + "github.com/lib/pq" ) type ArchiverRepository interface { @@ -99,9 +100,23 @@ func (d *DataAccessService) UpdateValidatorDashboardsArchiving(ctx context.Conte } func (d *DataAccessService) RemoveValidatorDashboards(ctx context.Context, dashboardIds []uint64) error { - // Delete the dashboard + // Delete the dashboards _, err := d.writerDb.ExecContext(ctx, ` DELETE FROM users_val_dashboards WHERE id = ANY($1) `, dashboardIds) + if err != nil { + return err + } + + var prefixes []string + for _, dashboardId := range dashboardIds { + prefixes = append(prefixes, fmt.Sprintf("%s:%d:%%", ValidatorDashboardEventPrefix, dashboardId)) + } + + // Remove all events related to the dashboards + _, err = d.userWriter.ExecContext(ctx, ` + DELETE FROM users_subscriptions WHERE event_filter LIKE ANY($1) + `, pq.Array(prefixes)) + return err } diff --git a/backend/pkg/notification/db.go b/backend/pkg/notification/db.go index ef865dd4e3..747ad6551f 100644 --- a/backend/pkg/notification/db.go +++ b/backend/pkg/notification/db.go @@ -16,7 +16,7 @@ import ( "github.com/lib/pq" ) -// Retrieves all subscription for a given event filter +// Retrieves all active subscriptions for a given event filter // Map key corresponds to the event filter which can be // a validator pubkey or an eth1 address (for RPL notifications) // or a list of validators for the tax report notifications @@ -144,11 +144,14 @@ func GetSubsForEventFilter(eventName types.EventName, lastSentFilter string, las FROM users_val_dashboards LEFT JOIN users_val_dashboards_groups ON users_val_dashboards_groups.dashboard_id = users_val_dashboards.id LEFT JOIN users_val_dashboards_validators ON users_val_dashboards_validators.dashboard_id = users_val_dashboards_groups.dashboard_id AND users_val_dashboards_validators.group_id = users_val_dashboards_groups.id - WHERE users_val_dashboards_validators.validator_index IS NOT NULL AND users_val_dashboards.id = ANY($1) + WHERE users_val_dashboards_validators.validator_index IS NOT NULL AND users_val_dashboards.id = ANY($1) AND users_val_dashboards.is_archived IS NULL `, pq.Array(dashboardConfigsToFetch)) if err != nil { return nil, fmt.Errorf("error getting dashboard definitions: %v", err) } + if len(dashboardDefinitions) == 0 { + return subMap, nil + } log.Infof("retrieved %d dashboard definitions", len(dashboardDefinitions)) // Now initialize the validator dashboard configuration map