diff --git a/core/api.go b/core/api.go index c3b0963..8b01b7a 100644 --- a/core/api.go +++ b/core/api.go @@ -85,7 +85,7 @@ type SuperGraph struct { allowList *allow.List encKey [32]byte hashSeed maphash.Seed - queries map[uint64]query + queries map[uint64]*query roles map[string]*Role getRole *sql.Stmt rmap map[uint64]resolvFn diff --git a/core/core.go b/core/core.go index fffb1a2..0cdeaa9 100644 --- a/core/core.go +++ b/core/core.go @@ -172,14 +172,15 @@ func (c *scontext) resolvePreparedSQL() ([]byte, *stmt, error) { h := maphash.Hash{} h.SetSeed(c.sg.hashSeed) + id := queryID(&h, c.res.name, role) - q, ok := c.sg.queries[queryID(&h, c.res.name, role)] + q, ok := c.sg.queries[id] if !ok { return nil, nil, errNotFound } if q.sd == nil { - q.Do(func() { c.sg.prepare(&q, role) }) + q.Do(func() { c.sg.prepare(q, role) }) if q.err != nil { return nil, nil, err diff --git a/core/internal/qcode/parse.go b/core/internal/qcode/parse.go index 6a1d254..3dfc82a 100644 --- a/core/internal/qcode/parse.go +++ b/core/internal/qcode/parse.go @@ -494,24 +494,6 @@ func (p *Parser) parseField(f *Field) error { return nil } -// func (p *Parser) parseInlineFragmentFields(st *Stack, fields []Field) ([]Field, error) { -// var err error - -// if p.peek(itemName) { -// p.ignore() -// // frag.On = p.vall(p.next()) -// } else { -// return nil, errors.New("inline fragment: missing table name after 'on' keyword") -// } - -// fields, err = p.parseNormalFields(st, fields) -// if err != nil { -// return nil, fmt.Errorf("inline fragment: %v", err) -// } - -// return fields, nil -// } - func (p *Parser) parseOpParams(args []Arg) ([]Arg, error) { for { if len(args) >= maxArgs { diff --git a/core/prepare.go b/core/prepare.go index a3588cd..fd61479 100644 --- a/core/prepare.go +++ b/core/prepare.go @@ -64,7 +64,7 @@ func (sg *SuperGraph) initPrepared() error { return fmt.Errorf("role query: %w", err) } - sg.queries = make(map[uint64]query) + sg.queries = make(map[uint64]*query) list, err := sg.allowList.Load() if err != nil { @@ -82,15 +82,15 @@ func (sg *SuperGraph) initPrepared() error { switch qt { case qcode.QTQuery: - sg.queries[queryID(&h, v.Name, "user")] = query{ai: v, qt: qt} + sg.queries[queryID(&h, v.Name, "user")] = &query{ai: v, qt: qt} if sg.anonExists { - sg.queries[queryID(&h, v.Name, "anon")] = query{ai: v, qt: qt} + sg.queries[queryID(&h, v.Name, "anon")] = &query{ai: v, qt: qt} } case qcode.QTMutation: for _, role := range sg.conf.Roles { - sg.queries[queryID(&h, v.Name, role.Name)] = query{ai: v, qt: qt} + sg.queries[queryID(&h, v.Name, role.Name)] = &query{ai: v, qt: qt} } } }