Don’t perform cpu intensive operations in SQL parser

This commit is contained in:
Tobie Morgan Hitchcock 2017-03-02 10:32:20 +00:00
parent 5fffc4bb73
commit 1157835a29
3 changed files with 10 additions and 9 deletions

View file

@ -15,10 +15,13 @@
package db package db
import ( import (
"golang.org/x/crypto/bcrypt"
"github.com/abcum/surreal/sql" "github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/item" "github.com/abcum/surreal/util/item"
"github.com/abcum/surreal/util/keys" "github.com/abcum/surreal/util/keys"
"github.com/abcum/surreal/util/pack" "github.com/abcum/surreal/util/pack"
"github.com/abcum/surreal/util/rand"
) )
func (e *executor) executeDefineNamespaceStatement(ast *sql.DefineNamespaceStatement) (out []interface{}, err error) { func (e *executor) executeDefineNamespaceStatement(ast *sql.DefineNamespaceStatement) (out []interface{}, err error) {
@ -48,6 +51,10 @@ func (e *executor) executeDefineDatabaseStatement(ast *sql.DefineDatabaseStateme
func (e *executor) executeDefineLoginStatement(ast *sql.DefineLoginStatement) (out []interface{}, err error) { func (e *executor) executeDefineLoginStatement(ast *sql.DefineLoginStatement) (out []interface{}, err error) {
ast.Code = rand.New(128)
ast.Pass, _ = bcrypt.GenerateFromPassword(ast.Pass, bcrypt.DefaultCost)
if ast.Kind == sql.NAMESPACE { if ast.Kind == sql.NAMESPACE {
// Set the namespace // Set the namespace
@ -122,6 +129,8 @@ func (e *executor) executeDefineTokenStatement(ast *sql.DefineTokenStatement) (o
func (e *executor) executeDefineScopeStatement(ast *sql.DefineScopeStatement) (out []interface{}, err error) { func (e *executor) executeDefineScopeStatement(ast *sql.DefineScopeStatement) (out []interface{}, err error) {
ast.Code = rand.New(128)
// Set the namespace // Set the namespace
nkey := &keys.NS{KV: ast.KV, NS: ast.NS} nkey := &keys.NS{KV: ast.KV, NS: ast.NS}
nval := &sql.DefineNamespaceStatement{Name: ast.NS} nval := &sql.DefineNamespaceStatement{Name: ast.NS}

View file

@ -46,11 +46,7 @@ func (p *parser) parseDefineLoginStatement() (stmt *DefineLoginStatement, err er
return nil, err return nil, err
} }
if stmt.Pass, err = p.parseBcrypt(); err != nil { if stmt.Pass, err = p.parseBinary(); err != nil {
return nil, err
}
if stmt.Code, err = p.parseRand(); err != nil {
return nil, err return nil, err
} }

View file

@ -55,10 +55,6 @@ func (p *parser) parseDefineScopeStatement() (stmt *DefineScopeStatement, err er
} }
if stmt.Code, err = p.parseRand(); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil { if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
return nil, err return nil, err
} }