Skip to content

Commit 42ba1cb

Browse files
committed
Add elapsed time to meta info
1 parent 9aeff22 commit 42ba1cb

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

soql/parser/parser.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ func init() {
2121
}
2222

2323
func Parse(s string) (*types.SoqlQuery, error) {
24+
meta := &types.SoqlQueryMeta{
25+
Version: "0.9",
26+
Date: time.Now().UTC(),
27+
Source: s,
28+
}
29+
2430
out, err := queryParser(*NewStringParserContext(s))
2531
if err != nil {
2632
pos := GetLineAndColPosition(s, out.SourcePosition, 4)
@@ -42,15 +48,14 @@ func Parse(s string) (*types.SoqlQuery, error) {
4248

4349
q := out.AstStack[0].Value.(types.SoqlQuery)
4450

45-
q.Meta = &types.SoqlQueryMeta{
46-
Version: "0.9",
47-
Date: time.Now().UTC(),
48-
Source: s,
49-
}
51+
q.Meta = meta
5052

5153
if err := postprocess.Normalize(&q); err != nil {
5254
return nil, err
5355
}
5456

57+
endDate := time.Now()
58+
q.Meta.ElapsedTime = endDate.Sub(q.Meta.Date)
59+
5560
return &q, nil
5661
}

soql/parser/parser_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ func TestParse2(t *testing.T) {
239239
return
240240
}
241241

242+
{
243+
s := got.Meta.ElapsedTime.String()
244+
t.Log(s)
245+
}
246+
242247
if !reflect.DeepEqual(got, tt.want) {
243248
// t.Errorf("Parse() = %v, want %v", got, tt.want)
244249
// return

soql/parser/types/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ type SoqlQueryGraphLeaf struct {
258258
type SoqlQueryMeta struct {
259259
Version string `json:"version,omitempty"` // format version
260260
Date time.Time `json:"date,omitempty"` // compiled datetime
261+
ElapsedTime time.Duration `json:"elapsedTime,omitempty"` // time taken to compile
261262
Source string `json:"source,omitempty"` // source
262263
MaxQueryDepth int `json:"maxQueryDepth,omitempty"` // max depth of query graph
263264
MaxViewDepth int `json:"maxViewDepth,omitempty"` // max depth of object graph
@@ -266,7 +267,7 @@ type SoqlQueryMeta struct {
266267
NextColumnId int `json:"nextColumnId,omitempty"` // next column id (a number of columns)
267268
QueryGraph map[int]SoqlQueryGraphLeaf `json:"queryGraph,omitempty"` // query graph (child -> parent)
268269
ViewGraph map[int]SoqlViewGraphLeaf `json:"viewGraph,omitempty"` // object graph (child -> parent)
269-
// TODO: MaxQueryDepth, Parameters, DateTimeLiterals
270+
// TODO: Parameters, DateTimeLiterals
270271
}
271272

272273
type SoqlQuery struct {

0 commit comments

Comments
 (0)