From 610efea05af593562297a47a9c59b0d94570d967 Mon Sep 17 00:00:00 2001 From: Yumin Xia Date: Wed, 30 Aug 2023 01:59:03 -0700 Subject: [PATCH] codegen: wpgx use CountIntent for cache hit rate stats --- internal/codegen/golang/templates/wpgx/copyfromCopy.tmpl | 1 + internal/codegen/golang/templates/wpgx/queryCode.tmpl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/internal/codegen/golang/templates/wpgx/copyfromCopy.tmpl b/internal/codegen/golang/templates/wpgx/copyfromCopy.tmpl index 3b5fe4416f..f0bce102ec 100644 --- a/internal/codegen/golang/templates/wpgx/copyfromCopy.tmpl +++ b/internal/codegen/golang/templates/wpgx/copyfromCopy.tmpl @@ -38,6 +38,7 @@ func (r iteratorFor{{.MethodName}}) Err() error { {{range .Comments}}//{{.}} {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) (int64, error) { + q.db.CountIntent("{{.UniqueLabel}}") return q.db.WCopyFrom(ctx, "{{.UniqueLabel}}", {{.TableIdentifierAsGoSlice}}, {{.Arg.ColumnNamesAsGoSlice}}, &iteratorFor{{.MethodName}}{rows: {{.Arg.Name}}}) } diff --git a/internal/codegen/golang/templates/wpgx/queryCode.tmpl b/internal/codegen/golang/templates/wpgx/queryCode.tmpl index 7fb715d735..65d49c01de 100644 --- a/internal/codegen/golang/templates/wpgx/queryCode.tmpl +++ b/internal/codegen/golang/templates/wpgx/queryCode.tmpl @@ -36,6 +36,7 @@ type {{.Ret.Type}} struct { {{- range .Ret.Struct.Fields}} {{range .Comments}}//{{.}} {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (*{{.Ret.Type}}, error) { + q.db.CountIntent("{{.UniqueLabel}}") {{- if eq .Option.Cache.Milliseconds 0}} row := q.db.WQueryRow(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) var {{.Ret.Name}} *{{.Ret.Type}} = new({{.Ret.Type}}) @@ -98,6 +99,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida {{range .Comments}}//{{.}} {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) ([]{{.Ret.Type}}, error) { + q.db.CountIntent("{{.UniqueLabel}}") {{- if eq .Option.Cache.Milliseconds 0}} rows, err := q.db.WQuery(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { @@ -177,6 +179,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida {{range .Comments}}//{{.}} {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) error { + q.db.CountIntent("{{.UniqueLabel}}") _, err := q.db.WExec(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { return err @@ -211,6 +214,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida {{range .Comments}}//{{.}} {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (int64, error) { + q.db.CountIntent("{{.UniqueLabel}}") result, err := q.db.WExec(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { return 0, err @@ -245,6 +249,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.Invalida {{range .Comments}}//{{.}} {{end -}} func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}} {{.InvalidateArgs}}) (pgconn.CommandTag, error) { + q.db.CountIntent("{{.UniqueLabel}}") rv, err := q.db.WExec(ctx, "{{.UniqueLabel}}", {{.ConstantName}}, {{.Arg.Params}}) if err != nil { return rv, err