Make db package more efficient
This commit is contained in:
parent
ae303d062c
commit
672d298e7e
4 changed files with 34 additions and 39 deletions
7
db/db.go
7
db/db.go
|
@ -255,12 +255,7 @@ func Process(fib *fibre.Context, ast *sql.Query, vars map[string]interface{}) (o
|
||||||
if !open {
|
if !open {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
out = append(out, &Response{
|
out = append(out, res)
|
||||||
Time: res.Time,
|
|
||||||
Status: res.Status,
|
|
||||||
Detail: res.Detail,
|
|
||||||
Result: res.Result,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -364,13 +364,6 @@ func (d *document) storeThing(ctx context.Context) (err error) {
|
||||||
|
|
||||||
defer d.ulock(ctx)
|
defer d.ulock(ctx)
|
||||||
|
|
||||||
// Check that the table should
|
|
||||||
// drop data being written.
|
|
||||||
|
|
||||||
if ok, err := d.shouldDrop(); ok {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that the rcord has been
|
// Check that the rcord has been
|
||||||
// changed, and if not, return.
|
// changed, and if not, return.
|
||||||
|
|
||||||
|
@ -378,6 +371,13 @@ func (d *document) storeThing(ctx context.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the table should
|
||||||
|
// drop data being written.
|
||||||
|
|
||||||
|
if ok, err := d.shouldDrop(); ok {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Write the value to the data
|
// Write the value to the data
|
||||||
// layer and return any errors.
|
// layer and return any errors.
|
||||||
|
|
||||||
|
|
12
db/lives.go
12
db/lives.go
|
@ -24,12 +24,6 @@ import (
|
||||||
// this table, and executes them in name order.
|
// this table, and executes them in name order.
|
||||||
func (d *document) lives(ctx context.Context, when method) (err error) {
|
func (d *document) lives(ctx context.Context, when method) (err error) {
|
||||||
|
|
||||||
// Get the ID of the current fibre
|
|
||||||
// connection so that we can check
|
|
||||||
// against the ID of live queries.
|
|
||||||
|
|
||||||
id := ctx.Value(ctxKeyId).(string)
|
|
||||||
|
|
||||||
// If this document has not changed
|
// If this document has not changed
|
||||||
// then there is no need to update
|
// then there is no need to update
|
||||||
// any registered live queries.
|
// any registered live queries.
|
||||||
|
@ -38,6 +32,12 @@ func (d *document) lives(ctx context.Context, when method) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the ID of the current fibre
|
||||||
|
// connection so that we can check
|
||||||
|
// against the ID of live queries.
|
||||||
|
|
||||||
|
id := ctx.Value(ctxKeyId).(string)
|
||||||
|
|
||||||
// Get the foreign read-only tables
|
// Get the foreign read-only tables
|
||||||
// specified for this table, and
|
// specified for this table, and
|
||||||
// update values which have changed.
|
// update values which have changed.
|
||||||
|
|
40
db/yield.go
40
db/yield.go
|
@ -25,48 +25,48 @@ import (
|
||||||
|
|
||||||
func (d *document) cold(ctx context.Context) (doc *data.Doc, err error) {
|
func (d *document) cold(ctx context.Context) (doc *data.Doc, err error) {
|
||||||
|
|
||||||
// If we are authenticated using DB, NS,
|
// If we are not authenticated using DB,
|
||||||
// or KV permissions level, then we can
|
// NS, or KV level, then we need to check
|
||||||
// return the document without copying.
|
// document permissions for this query.
|
||||||
|
|
||||||
if k, ok := ctx.Value(ctxKeyKind).(cnf.Kind); ok {
|
if k, ok := ctx.Value(ctxKeyKind).(cnf.Kind); ok {
|
||||||
if k < cnf.AuthSC {
|
if k == cnf.AuthSC {
|
||||||
return d.initial, nil
|
if err = d.perms(ctx, d.initial); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we need to create a copy
|
// We need to copy the document so that
|
||||||
// of the document so that we can add
|
// we can add and remove the fields which
|
||||||
// and remove fields before outputting.
|
// are relevant to the particular query.
|
||||||
|
|
||||||
doc = d.initial.Copy()
|
doc = d.initial.Copy()
|
||||||
|
|
||||||
err = d.perms(ctx, doc)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *document) cnow(ctx context.Context) (doc *data.Doc, err error) {
|
func (d *document) cnow(ctx context.Context) (doc *data.Doc, err error) {
|
||||||
|
|
||||||
// If we are authenticated using DB, NS,
|
// If we are not authenticated using DB,
|
||||||
// or KV permissions level, then we can
|
// NS, or KV level, then we need to check
|
||||||
// return the document without copying.
|
// document permissions for this query.
|
||||||
|
|
||||||
if k, ok := ctx.Value(ctxKeyKind).(cnf.Kind); ok {
|
if k, ok := ctx.Value(ctxKeyKind).(cnf.Kind); ok {
|
||||||
if k < cnf.AuthSC {
|
if k == cnf.AuthSC {
|
||||||
return d.current, nil
|
if err = d.perms(ctx, d.current); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we need to create a copy
|
// We need to copy the document so that
|
||||||
// of the document so that we can add
|
// we can add and remove the fields which
|
||||||
// and remove fields before outputting.
|
// are relevant to the particular query.
|
||||||
|
|
||||||
doc = d.current.Copy()
|
doc = d.current.Copy()
|
||||||
|
|
||||||
err = d.perms(ctx, doc)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue