Ensure linked records are fetched using the same query version
This commit is contained in:
parent
14c0d93635
commit
99d050b238
3 changed files with 30 additions and 11 deletions
16
db/fetch.go
16
db/fetch.go
|
@ -339,12 +339,18 @@ func (e *executor) fetchPaths(ctx context.Context, doc *data.Doc, exprs ...sql.E
|
|||
|
||||
func (e *executor) fetchThing(ctx context.Context, val *sql.Thing, doc *data.Doc) (interface{}, error) {
|
||||
|
||||
ver, err := e.fetchVersion(ctx, ctx.Value(ctxKeyVersion))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := e.executeSelect(ctx, &sql.SelectStatement{
|
||||
KV: cnf.Settings.DB.Base,
|
||||
NS: ctx.Value(ctxKeyNs).(string),
|
||||
DB: ctx.Value(ctxKeyDb).(string),
|
||||
Expr: []*sql.Field{{Expr: &sql.All{}}},
|
||||
What: []sql.Expr{val},
|
||||
Version: sql.Expr(ver),
|
||||
Parallel: 1,
|
||||
})
|
||||
|
||||
|
@ -362,12 +368,18 @@ func (e *executor) fetchThing(ctx context.Context, val *sql.Thing, doc *data.Doc
|
|||
|
||||
func (e *executor) fetchArray(ctx context.Context, val []interface{}, doc *data.Doc) (interface{}, error) {
|
||||
|
||||
ver, err := e.fetchVersion(ctx, ctx.Value(ctxKeyVersion))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := e.executeSelect(ctx, &sql.SelectStatement{
|
||||
KV: cnf.Settings.DB.Base,
|
||||
NS: ctx.Value(ctxKeyNs).(string),
|
||||
DB: ctx.Value(ctxKeyDb).(string),
|
||||
Expr: []*sql.Field{{Expr: &sql.All{}}},
|
||||
What: []sql.Expr{val},
|
||||
Version: sql.Expr(ver),
|
||||
Parallel: 1,
|
||||
})
|
||||
|
||||
|
@ -442,6 +454,10 @@ func (e *executor) fetchStart(ctx context.Context, val sql.Expr) (int, error) {
|
|||
|
||||
func (e *executor) fetchVersion(ctx context.Context, val sql.Expr) (int64, error) {
|
||||
|
||||
if v, ok := val.(int64); ok {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
v, err := e.fetch(ctx, val, nil)
|
||||
if err != nil {
|
||||
return math.MaxInt64, err
|
||||
|
|
|
@ -24,6 +24,8 @@ import (
|
|||
|
||||
func (e *executor) executeSelect(ctx context.Context, stm *sql.SelectStatement) ([]interface{}, error) {
|
||||
|
||||
ctx = context.WithValue(ctx, ctxKeyVersion, stm.Version)
|
||||
|
||||
var what sql.Exprs
|
||||
|
||||
for _, val := range stm.What {
|
||||
|
|
23
db/vars.go
23
db/vars.go
|
@ -35,17 +35,18 @@ const (
|
|||
)
|
||||
|
||||
const (
|
||||
ctxKeyId = "id"
|
||||
ctxKeyNs = "ns"
|
||||
ctxKeyDb = "db"
|
||||
ctxKeyDive = "dive"
|
||||
ctxKeyVars = "vars"
|
||||
ctxKeySubs = "subs"
|
||||
ctxKeySpec = "spec"
|
||||
ctxKeyKeep = "keep"
|
||||
ctxKeyAuth = "auth"
|
||||
ctxKeyKind = "kind"
|
||||
ctxKeyScope = "scope"
|
||||
ctxKeyId = "id"
|
||||
ctxKeyNs = "ns"
|
||||
ctxKeyDb = "db"
|
||||
ctxKeyDive = "dive"
|
||||
ctxKeyVars = "vars"
|
||||
ctxKeySubs = "subs"
|
||||
ctxKeySpec = "spec"
|
||||
ctxKeyKeep = "keep"
|
||||
ctxKeyAuth = "auth"
|
||||
ctxKeyKind = "kind"
|
||||
ctxKeyScope = "scope"
|
||||
ctxKeyVersion = "version"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
Loading…
Reference in a new issue