From fa9ffc5361016571af0189203003f4be630f2ca2 Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Sat, 31 Oct 2020 00:55:17 -0400 Subject: 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 Run-TryBot: Jonathan Amsterdam TryBot-Result: kokoro Reviewed-by: Jamal Carvalho Reviewed-by: Julie Qiu --- internal/postgres/insert_module.go | 2 +- internal/postgres/search.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'internal/postgres') 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 } -- cgit v1.3-5-g9baa