Fix the REPL-clearing-state bug.
This commit is contained in:
parent
9cb8cdc952
commit
73e9e1edc3
4 changed files with 35 additions and 7 deletions
|
|
@ -69,7 +69,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, config *cfg.CayleyCo
|
|||
case "gremlin":
|
||||
fallthrough
|
||||
default:
|
||||
ses = gremlin.NewGremlinSession(ts, config.GremlinTimeout)
|
||||
ses = gremlin.NewGremlinSession(ts, config.GremlinTimeout, true)
|
||||
}
|
||||
inputBf := bufio.NewReader(os.Stdin)
|
||||
line := ""
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func (api *Api) ServeV1Query(w http.ResponseWriter, r *http.Request, params http
|
|||
var ses graph.HttpSession
|
||||
switch params.ByName("query_lang") {
|
||||
case "gremlin":
|
||||
ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout)
|
||||
ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout, false)
|
||||
case "mql":
|
||||
ses = mql.NewMqlSession(api.ts)
|
||||
default:
|
||||
|
|
@ -118,7 +118,7 @@ func (api *Api) ServeV1Shape(w http.ResponseWriter, r *http.Request, params http
|
|||
var ses graph.HttpSession
|
||||
switch params.ByName("query_lang") {
|
||||
case "gremlin":
|
||||
ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout)
|
||||
ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout, false)
|
||||
case "mql":
|
||||
ses = mql.NewMqlSession(api.ts)
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -37,15 +37,19 @@ type GremlinSession struct {
|
|||
script *otto.Script
|
||||
doHalt bool
|
||||
timeoutSec time.Duration
|
||||
emptyEnv *otto.Otto
|
||||
}
|
||||
|
||||
func NewGremlinSession(inputTripleStore graph.TripleStore, timeoutSec int) *GremlinSession {
|
||||
func NewGremlinSession(inputTripleStore graph.TripleStore, timeoutSec int, persist bool) *GremlinSession {
|
||||
var g GremlinSession
|
||||
g.ts = inputTripleStore
|
||||
g.env = BuildGremlinEnv(&g)
|
||||
g.limit = -1
|
||||
g.count = 0
|
||||
g.lookingForQueryShape = false
|
||||
if persist {
|
||||
g.emptyEnv = g.env
|
||||
}
|
||||
if timeoutSec < 0 {
|
||||
g.timeoutSec = time.Duration(-1)
|
||||
} else {
|
||||
|
|
@ -127,7 +131,7 @@ func (g *GremlinSession) runUnsafe(input interface{}) (otto.Value, error) {
|
|||
g.env.Interrupt <- func() {
|
||||
panic(halt)
|
||||
}
|
||||
g.env = nil
|
||||
g.env = g.emptyEnv
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
@ -159,7 +163,7 @@ func (g *GremlinSession) ExecInput(input string, out chan interface{}, limit int
|
|||
}
|
||||
g.currentChannel = nil
|
||||
g.script = nil
|
||||
g.env = nil
|
||||
g.env = g.emptyEnv
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue