Skip to content

Commit 6c1dc28

Browse files
authored
edgeql-go: only fetch protocol version once (#396)
This is a minor optimization.
1 parent 4a2f392 commit 6c1dc28

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

cmd/edgeql-go/main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"time"
3838

3939
"github.com/geldata/gel-go/gelcfg"
40+
"github.com/geldata/gel-go/internal"
4041
gelint "github.com/geldata/gel-go/internal/client"
4142
"github.com/geldata/gel-go/internal/descriptor"
4243
toml "github.com/pelletier/go-toml/v2"
@@ -62,10 +63,11 @@ func usage() {
6263
}
6364

6465
type cmdConfig struct {
65-
mixedCaps bool
66-
pubfuncs bool
67-
pubtypes bool
68-
rawmessage bool
66+
mixedCaps bool
67+
pubfuncs bool
68+
pubtypes bool
69+
rawmessage bool
70+
protocolVersion internal.ProtocolVersion
6971
}
7072

7173
func main() {
@@ -110,6 +112,11 @@ func main() {
110112
log.Println("connected")
111113
}
112114

115+
cfg.protocolVersion, err = gelint.ProtocolVersion(ctx, c)
116+
if err != nil {
117+
log.Fatalf("error determining the protocol version: %s", err)
118+
}
119+
113120
fileQueue := queueFilesInBackground()
114121

115122
t, err := template.New("files.template").

cmd/edgeql-go/query.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,9 @@ func newQuery(
8181
log.Fatalf("error reading %q: %s", qryFile, err)
8282
}
8383

84-
v, err := gelint.ProtocolVersion(ctx, p)
85-
if err != nil {
86-
log.Fatalf("error determining the protocol version: %s", err)
87-
}
88-
8984
var qs querySetup
9085

91-
if v.GTE(internal.ProtocolVersion{Major: 2, Minor: 0}) {
86+
if cfg.protocolVersion.GTE(internal.ProtocolVersion{Major: 2, Minor: 0}) {
9287
qs = &queryConfigV2{}
9388
} else {
9489
qs = &queryConfigV1{}

0 commit comments

Comments
 (0)