diff options
| author | Julie Qiu <julie@golang.org> | 2021-04-19 13:13:21 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2021-04-19 18:32:29 +0000 |
| commit | 26982222eb6aad12a71e7236da86bf9306db5cbc (patch) | |
| tree | e6f98faff3c79f1126d5930e98325003585e640e /internal/postgres | |
| parent | f934b6307518a09a5b205e7dd5bb2c3a0126755d (diff) | |
| download | go-x-pkgsite-26982222eb6aad12a71e7236da86bf9306db5cbc.tar.xz | |
internal/postgres: add stats for GetUnit and GetUnitMeta
Additional stats are added to GetUnit and GetUnitMeta to debug latency
issues.
Change-Id: I07abb3191af2e5802670390029f148fa78863679
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/311429
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/postgres')
| -rw-r--r-- | internal/postgres/unit.go | 54 | ||||
| -rw-r--r-- | internal/postgres/version.go | 4 |
2 files changed, 38 insertions, 20 deletions
diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go index 8444852b..ac161012 100644 --- a/internal/postgres/unit.go +++ b/internal/postgres/unit.go @@ -52,6 +52,7 @@ func (db *DB) GetUnitMeta(ctx context.Context, fullPath, requestedModulePath, re func (db *DB) getUnitMetaWithKnownLatestVersion(ctx context.Context, fullPath, modulePath, version string, lmv *internal.LatestModuleVersions) (_ *internal.UnitMeta, err error) { defer derrors.WrapStack(&err, "getUnitMetaKnownVersion") + defer middleware.ElapsedStat(ctx, "getUnitMetaKnownVersion")() query := squirrel.Select( "m.module_path", @@ -142,6 +143,7 @@ func (db *DB) getLatestUnitVersion(ctx context.Context, fullPath, requestedModul modulePath, latestVersion string, lmv *internal.LatestModuleVersions, err error) { defer derrors.WrapStack(&err, "getLatestUnitVersion(%q, %q)", fullPath, requestedModulePath) + defer middleware.ElapsedStat(ctx, "getLatestUnitVersion")() modPaths := []string{requestedModulePath} // If we don't know the module path, try each possible module path from longest to shortest. @@ -434,6 +436,7 @@ func (db *DB) getUnitWithAllFields(ctx context.Context, um *internal.UnitMeta) ( r internal.Readme u internal.Unit ) + end := middleware.ElapsedStat(ctx, "getUnitWithAllFields-readme-and-imports") err = db.db.QueryRow(ctx, query, um.Path, um.ModulePath, um.Version).Scan( &unitID, database.NullIsEmpty(&r.Filepath), @@ -451,39 +454,52 @@ func (db *DB) getUnitWithAllFields(ctx context.Context, um *internal.UnitMeta) ( default: return nil, err } + end() + // Get documentation. + docs, err := db.getDocumentation(ctx, unitID) + if err != nil { + return nil, err + } + u.Documentation = docs + + // Get other info. + pkgs, err := db.getPackagesInUnit(ctx, um.Path, um.ModulePath, um.Version) + if err != nil { + return nil, err + } + u.Subdirectories = pkgs + u.UnitMeta = *um + return &u, nil +} + +func (db *DB) getDocumentation(ctx context.Context, unitID int) (_ []*internal.Documentation, err error) { + defer derrors.WrapStack(&err, "getDocumentation(ctx, %d)", unitID) + defer middleware.ElapsedStat(ctx, "getDocumentation")() + + var docs []*internal.Documentation // Get documentation. There can be multiple rows. - query = ` + query := ` SELECT goos, goarch, synopsis, source FROM documentation - WHERE unit_id = $1 - ` - err = db.db.RunQuery(ctx, query, func(rows *sql.Rows) error { + WHERE unit_id = $1` + if err := db.db.RunQuery(ctx, query, func(rows *sql.Rows) error { var d internal.Documentation if err := rows.Scan(&d.GOOS, &d.GOARCH, &d.Synopsis, &d.Source); err != nil { return err } - u.Documentation = append(u.Documentation, &d) + docs = append(docs, &d) return nil - }, unitID) - if err != nil { + }, unitID); err != nil { return nil, err } // Sort documentation by GOOS/GOARCH. - sort.Slice(u.Documentation, func(i, j int) bool { - ci := u.Documentation[i].BuildContext() - cj := u.Documentation[j].BuildContext() + sort.Slice(docs, func(i, j int) bool { + ci := docs[i].BuildContext() + cj := docs[j].BuildContext() return internal.CompareBuildContexts(ci, cj) < 0 }) - - // Get other info. - pkgs, err := db.getPackagesInUnit(ctx, um.Path, um.ModulePath, um.Version) - if err != nil { - return nil, err - } - u.Subdirectories = pkgs - u.UnitMeta = *um - return &u, nil + return docs, nil } type dbPath struct { diff --git a/internal/postgres/version.go b/internal/postgres/version.go index a1bed6d0..76bf5117 100644 --- a/internal/postgres/version.go +++ b/internal/postgres/version.go @@ -18,6 +18,7 @@ import ( "golang.org/x/pkgsite/internal/database" "golang.org/x/pkgsite/internal/derrors" "golang.org/x/pkgsite/internal/log" + "golang.org/x/pkgsite/internal/middleware" "golang.org/x/pkgsite/internal/version" "golang.org/x/sync/errgroup" ) @@ -322,7 +323,8 @@ func (db *DB) unitExistsAtLatest(ctx context.Context, unitPath, modulePath strin } func (db *DB) getMultiLatestModuleVersions(ctx context.Context, modulePaths []string) (lmvs []*internal.LatestModuleVersions, err error) { - derrors.WrapStack(&err, "getMultiLatestModuleVersions(%v)", modulePaths) + defer derrors.WrapStack(&err, "getMultiLatestModuleVersions(%v)", modulePaths) + defer middleware.ElapsedStat(ctx, "getMultiLatestModuleVersions")() collect := func(rows *sql.Rows) error { var ( |
