Skip to content

Commit

Permalink
cleanup graphql code
Browse files Browse the repository at this point in the history
- removed debug print
- removed redundant nil check on Metadata() result
- updated Metadata comment regarding return values
  • Loading branch information
mastercactapus committed Apr 1, 2024
1 parent 26e067e commit 1effb27
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
6 changes: 3 additions & 3 deletions alert/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type metadataDBFormat struct {
AlertMetaV1 map[string]string
}

// Metadata returns the metadata for a single alert.
func (s *Store) Metadata(ctx context.Context, db gadb.DBTX, alertID int) (map[string]string, error) {
err := permission.LimitCheckAny(ctx, permission.System, permission.User)
// Metadata returns the metadata for a single alert. If err == nil, meta is guaranteed to be non-nil. If the alert has no metadata, an empty map is returned.
func (s *Store) Metadata(ctx context.Context, db gadb.DBTX, alertID int) (meta map[string]string, err error) {
err = permission.LimitCheckAny(ctx, permission.System, permission.User)
if err != nil {
return nil, err
}
Expand Down
6 changes: 1 addition & 5 deletions graphql2/graphqlapp/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func (a *Alert) Meta(ctx context.Context, alert *alert.Alert) ([]graphql2.AlertM
alertMeta = append(alertMeta, graphql2.AlertMetadata{Key: k, Value: v})
}
sort.Slice(alertMeta, func(i, j int) bool {
return strings.ToLower(alertMeta[i].Key) < strings.ToLower(alertMeta[j].Key)
return alertMeta[i].Key < alertMeta[j].Key
})
return alertMeta, nil
}
Expand All @@ -637,9 +637,5 @@ func (a *Alert) MetaValue(ctx context.Context, alert *alert.Alert, key string) (
return "", err
}

if md == nil {
return "", nil
}

return md[key], nil
}
2 changes: 0 additions & 2 deletions graphql2/graphqlapp/dataloaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package graphqlapp

import (
context "context"
"fmt"
"io"

"github.com/google/uuid"
Expand Down Expand Up @@ -175,7 +174,6 @@ func (app *App) FindOnePolicy(ctx context.Context, id string) (*escalation.Polic
func (app *App) FindOneService(ctx context.Context, id string) (*service.Service, error) {
loader, ok := ctx.Value(dataLoaderKeyService).(*dataloader.Loader[string, service.Service])
if !ok {
fmt.Println("using service store")
return app.ServiceStore.FindOne(ctx, id)
}

Expand Down

0 comments on commit 1effb27

Please sign in to comment.