aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2024-08-30 09:28:08 -0400
committerJonathan Amsterdam <jba@google.com>2024-09-04 12:20:54 +0000
commitf5afe0245fffc029e6a9ec3010b9ff04107b171a (patch)
tree62cf5231691851be4b78cfd5774d74d3f19a09f7 /internal/postgres/insert_module.go
parent6851d87f22a7daa606b7fccfd67e6a60718e4b31 (diff)
downloadgo-x-pkgsite-f5afe0245fffc029e6a9ec3010b9ff04107b171a.tar.xz
several: use stdlib functions
Replace some functions with simpler code that uses recent functions added to the standard library. Change-Id: Ifcd570679a897fb165a4307c7ce9f0f53fccea05 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/609116 kokoro-CI: kokoro <noreply+kokoro@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'internal/postgres/insert_module.go')
-rw-r--r--internal/postgres/insert_module.go14
1 files changed, 4 insertions, 10 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index a9182507..1db5e72f 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -12,6 +12,8 @@ import (
"fmt"
"hash/fnv"
"io"
+ "maps"
+ "slices"
"sort"
"strings"
"unicode/utf8"
@@ -442,15 +444,7 @@ func insertPaths(ctx context.Context, tx *database.DB, m *internal.Module) (path
curPathsSet[internal.V1Path(u.Path, m.ModulePath)] = true
curPathsSet[internal.SeriesPathForModule(m.ModulePath)] = true
}
- return upsertPaths(ctx, tx, stringSetToSlice(curPathsSet))
-}
-
-func stringSetToSlice(m map[string]bool) []string {
- var s []string
- for e := range m {
- s = append(s, e)
- }
- return s
+ return upsertPaths(ctx, tx, slices.Collect(maps.Keys(curPathsSet)))
}
func insertUnits(ctx context.Context, db *database.DB, unitValues []any) (pathIDToUnitID map[int]int, err error) {
@@ -581,7 +575,7 @@ func insertImports(ctx context.Context, tx *database.DB,
importPathSet[imp] = true
}
}
- pathToID, err := upsertPaths(ctx, tx, stringSetToSlice(importPathSet))
+ pathToID, err := upsertPaths(ctx, tx, slices.Collect(maps.Keys(importPathSet)))
if err != nil {
return err
}