diff options
| author | Jonathan Amsterdam <jba@google.com> | 2020-10-31 00:55:17 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2020-11-03 18:24:52 +0000 |
| commit | fa9ffc5361016571af0189203003f4be630f2ca2 (patch) | |
| tree | a2576c3e2d22bf2e18ec4e1972fd18cf8c4a9fc5 /internal/postgres | |
| parent | 8fa21ce22192746f42f770eb66cc638a056f1c5d (diff) | |
| download | go-x-pkgsite-fa9ffc5361016571af0189203003f4be630f2ca2.tar.xz | |
internal/postgres: make UpsertSearchDocument a method
We will need something (a column name) from the postgres.DB in the
next CL.
Change-Id: I9497aa1641107e92965e715791014680346567f1
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/267237
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres')
| -rw-r--r-- | internal/postgres/insert_module.go | 2 | ||||
| -rw-r--r-- | internal/postgres/search.go | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index 6eefd41b..fcb38933 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -149,7 +149,7 @@ func (db *DB) saveModule(ctx context.Context, m *internal.Module) (err error) { return err } // Insert the module's packages into search_documents. - return upsertSearchDocuments(ctx, tx, m) + return db.upsertSearchDocuments(ctx, tx, m) }) } diff --git a/internal/postgres/search.go b/internal/postgres/search.go index 713ad433..d9648dff 100644 --- a/internal/postgres/search.go +++ b/internal/postgres/search.go @@ -445,8 +445,8 @@ var upsertSearchStatement = fmt.Sprintf(` // upsertSearchDocuments adds search information for mod ot the search_documents table. // It assumes that all non-redistributable data has been removed from mod. -func upsertSearchDocuments(ctx context.Context, db *database.DB, mod *internal.Module) (err error) { - defer derrors.Wrap(&err, "UpsertSearchDocuments(ctx, %q)", mod.ModulePath) +func (db *DB) upsertSearchDocuments(ctx context.Context, ddb *database.DB, mod *internal.Module) (err error) { + defer derrors.Wrap(&err, "upsertSearchDocuments(ctx, %q)", mod.ModulePath) ctx, span := trace.StartSpan(ctx, "UpsertSearchDocuments") defer span.End() for _, pkg := range mod.Packages() { @@ -464,7 +464,7 @@ func upsertSearchDocuments(ctx context.Context, db *database.DB, mod *internal.M args.ReadmeFilePath = pkg.Readme.Filepath args.ReadmeContents = pkg.Readme.Contents } - if err := UpsertSearchDocument(ctx, db, args); err != nil { + if err := db.UpsertSearchDocument(ctx, ddb, args); err != nil { return err } } @@ -484,8 +484,8 @@ type upsertSearchDocumentArgs struct { // // The given module should have already been validated via a call to // validateModule. -func UpsertSearchDocument(ctx context.Context, db *database.DB, args upsertSearchDocumentArgs) (err error) { - defer derrors.Wrap(&err, "UpsertSearchDocument(ctx, db, %q, %q)", args.PackagePath, args.ModulePath) +func (db *DB) UpsertSearchDocument(ctx context.Context, ddb *database.DB, args upsertSearchDocumentArgs) (err error) { + defer derrors.Wrap(&err, "DB.UpsertSearchDocument(ctx, ddb, %q, %q)", args.PackagePath, args.ModulePath) // Only summarize the README if the package and module have the same path. if args.PackagePath != args.ModulePath { @@ -494,7 +494,7 @@ func UpsertSearchDocument(ctx context.Context, db *database.DB, args upsertSearc } pathTokens := strings.Join(GeneratePathTokens(args.PackagePath), " ") sectionB, sectionC, sectionD := SearchDocumentSections(args.Synopsis, args.ReadmeFilePath, args.ReadmeContents) - _, err = db.Exec(ctx, upsertSearchStatement, args.PackagePath, pathTokens, sectionB, sectionC, sectionD) + _, err = ddb.Exec(ctx, upsertSearchStatement, args.PackagePath, pathTokens, sectionB, sectionC, sectionD) return err } |
