aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2020-06-09 07:05:14 -0400
committerJonathan Amsterdam <jba@google.com>2020-06-09 15:01:27 +0000
commit465b4fd31d6406fa613cc74a27c4194927b77ea0 (patch)
tree28fb471c0739e84957d792f6b1790ec8e16bb6ed /internal/postgres/insert_module.go
parentf1715b0ed5b6a00a4a47e772e4571543c296e899 (diff)
downloadgo-x-pkgsite-465b4fd31d6406fa613cc74a27c4194927b77ea0.tar.xz
internal/postgres: move bulk inserts out of loops
Some BulkInserts were being called inside a loop when they should be outside. Change-Id: I5c00c45c24784a69e5b273c54eecbc63a8ae0634 Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/766239 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Julie Qiu <julieqiu@google.com>
Diffstat (limited to 'internal/postgres/insert_module.go')
-rw-r--r--internal/postgres/insert_module.go29
1 files changed, 9 insertions, 20 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index ff4de02e..4dc6f3a4 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -473,6 +473,7 @@ func insertDirectories(ctx context.Context, db *database.DB, m *internal.Module,
// same module, which happens regularly.
sort.Strings(paths)
if len(pathToReadme) > 0 {
+ log.Debugf(ctx, "memory before inserting into readmes: %dM", allocMeg())
var readmeValues []interface{}
for _, path := range paths {
readme, ok := pathToReadme[path]
@@ -481,20 +482,15 @@ func insertDirectories(ctx context.Context, db *database.DB, m *internal.Module,
}
id := pathToID[path]
readmeValues = append(readmeValues, id, readme.Filepath, makeValidUnicode(readme.Contents))
- readmeCols := []string{
- "path_id",
- "file_path",
- "contents",
- }
- log.Debugf(ctx, "memory before inserting into readmes: %dM", allocMeg())
-
- if err := db.BulkInsert(ctx, "readmes", readmeCols, readmeValues, database.OnConflictDoNothing); err != nil {
- return err
- }
+ }
+ readmeCols := []string{"path_id", "file_path", "contents"}
+ if err := db.BulkInsert(ctx, "readmes", readmeCols, readmeValues, database.OnConflictDoNothing); err != nil {
+ return err
}
}
if len(pathToDoc) > 0 {
+ log.Debugf(ctx, "memory before inserting into documentation: %dM", allocMeg())
var docValues []interface{}
for _, path := range paths {
doc, ok := pathToDoc[path]
@@ -511,12 +507,12 @@ func insertDirectories(ctx context.Context, db *database.DB, m *internal.Module,
"synopsis",
"html",
}
- log.Debugf(ctx, "memory before inserting into documentation: %dM", allocMeg())
if err := db.BulkInsert(ctx, "documentation", docCols, docValues, database.OnConflictDoNothing); err != nil {
return err
}
}
+ log.Debugf(ctx, "memory before inserting into package_imports: %dM", allocMeg())
var importValues []interface{}
for _, pkgPath := range paths {
imports, ok := pathToImports[pkgPath]
@@ -527,16 +523,9 @@ func insertDirectories(ctx context.Context, db *database.DB, m *internal.Module,
for _, toPath := range imports {
importValues = append(importValues, id, toPath)
}
- importCols := []string{
- "path_id",
- "to_path",
- }
- log.Debugf(ctx, "memory before inserting into package_imports: %dM", allocMeg())
- if err := db.BulkInsert(ctx, "package_imports", importCols, importValues, database.OnConflictDoNothing); err != nil {
- return err
- }
}
- return nil
+ importCols := []string{"path_id", "to_path"}
+ return db.BulkInsert(ctx, "package_imports", importCols, importValues, database.OnConflictDoNothing)
}
// lock obtains an exclusive, transaction-scoped advisory lock on modulePath.