diff --git a/appview/db/email.go b/appview/db/email.go index 1d7fba63..d32c6b28 100644 --- a/appview/db/email.go +++ b/appview/db/email.go @@ -67,21 +67,21 @@ func GetDidForEmail(e Execer, em string) (string, error) { return did, nil } -func GetDidsForEmails(e Execer, ems []string) ([]string, error) { +func GetEmailToDid(e Execer, ems []string) (map[string]string, error) { if len(ems) == 0 { - return []string{}, nil + return make(map[string]string), nil } // Create placeholders for the IN clause placeholders := make([]string, len(ems)) - args := make([]interface{}, len(ems)) + args := make([]any, len(ems)) for i, em := range ems { placeholders[i] = "?" args[i] = em } query := ` - select did + select email, did from emails where email in (` + strings.Join(placeholders, ",") + `) ` @@ -92,20 +92,21 @@ func GetDidsForEmails(e Execer, ems []string) ([]string, error) { } defer rows.Close() - var dids []string + assoc := make(map[string]string) + for rows.Next() { - var did string - if err := rows.Scan(&did); err != nil { + var email, did string + if err := rows.Scan(&email, &did); err != nil { return nil, err } - dids = append(dids, did) + assoc[email] = did } if err := rows.Err(); err != nil { return nil, err } - return dids, nil + return assoc, nil } func GetVerificationCodeForEmail(e Execer, did string, email string) (string, error) { diff --git a/appview/pages/templates/repo/commit.html b/appview/pages/templates/repo/commit.html index 56a2009a..ffde4a0b 100644 --- a/appview/pages/templates/repo/commit.html +++ b/appview/pages/templates/repo/commit.html @@ -20,9 +20,10 @@

- {{ if index .EmailToDidOrHandle $commit.Author.Email }} - {{ $handle := index .EmailToDidOrHandle $commit.Author.Email }} - @{{ $handle }} + {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} + + {{ if $didOrHandle }} + {{ $didOrHandle }} {{ else }} {{ $commit.Author.Name }} {{ end }} diff --git a/appview/pages/templates/repo/index.html b/appview/pages/templates/repo/index.html index 95eb4aee..d4b4c0c5 100644 --- a/appview/pages/templates/repo/index.html +++ b/appview/pages/templates/repo/index.html @@ -164,11 +164,11 @@ class="mx-2 before:content-['·'] before:select-none" > - {{ $handle := index $.EmailToDidOrHandle .Author.Email }} + {{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }} {{ if $handle }}@{{ $handle }}{{ else }}{{ .Author.Name }}{{ end }}{{ if $didOrHandle }}{{ $didOrHandle }}{{ else }}{{ .Author.Name }}{{ end }}

- {{ $handle := index $.EmailToDidOrHandle $commit.Author.Email }} - {{ if $handle }} + {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} + {{ if $didOrHandle }} @{{ $handle }}{{ $didOrHandle }} {{ else }} - {{ $handle := index $.EmailToDidOrHandle .Author.Email }} - {{ if $handle }} + {{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }} + {{ if $didOrHandle }} @{{ $handle }}{{ $didOrHandle }} {{ else }}