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 {
|
||||
return
|
||||
}
|
||||
out = append(out, &Response{
|
||||
Time: res.Time,
|
||||
Status: res.Status,
|
||||
Detail: res.Detail,
|
||||
Result: res.Result,
|
||||
})
|
||||
out = append(out, res)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -364,13 +364,6 @@ func (d *document) storeThing(ctx context.Context) (err error) {
|
|||
|
||||
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
|
||||
// changed, and if not, return.
|
||||
|
||||
|
@ -378,6 +371,13 @@ func (d *document) storeThing(ctx context.Context) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Check that the table should
|
||||
// drop data being written.
|
||||
|
||||
if ok, err := d.shouldDrop(); ok {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write the value to the data
|
||||
// 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.
|
||||
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
|
||||
// then there is no need to update
|
||||
// any registered live queries.
|
||||
|
@ -38,6 +32,12 @@ func (d *document) lives(ctx context.Context, when method) (err error) {
|
|||
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
|
||||
// specified for this table, and
|
||||
// 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) {
|
||||
|
||||
// If we are authenticated using DB, NS,
|
||||
// or KV permissions level, then we can
|
||||
// return the document without copying.
|
||||
// If we are not authenticated using DB,
|
||||
// NS, or KV level, then we need to check
|
||||
// document permissions for this query.
|
||||
|
||||
if k, ok := ctx.Value(ctxKeyKind).(cnf.Kind); ok {
|
||||
if k < cnf.AuthSC {
|
||||
return d.initial, nil
|
||||
if k == cnf.AuthSC {
|
||||
if err = d.perms(ctx, d.initial); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, we need to create a copy
|
||||
// of the document so that we can add
|
||||
// and remove fields before outputting.
|
||||
// We need to copy the document so that
|
||||
// we can add and remove the fields which
|
||||
// are relevant to the particular query.
|
||||
|
||||
doc = d.initial.Copy()
|
||||
|
||||
err = d.perms(ctx, doc)
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (d *document) cnow(ctx context.Context) (doc *data.Doc, err error) {
|
||||
|
||||
// If we are authenticated using DB, NS,
|
||||
// or KV permissions level, then we can
|
||||
// return the document without copying.
|
||||
// If we are not authenticated using DB,
|
||||
// NS, or KV level, then we need to check
|
||||
// document permissions for this query.
|
||||
|
||||
if k, ok := ctx.Value(ctxKeyKind).(cnf.Kind); ok {
|
||||
if k < cnf.AuthSC {
|
||||
return d.current, nil
|
||||
if k == cnf.AuthSC {
|
||||
if err = d.perms(ctx, d.current); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, we need to create a copy
|
||||
// of the document so that we can add
|
||||
// and remove fields before outputting.
|
||||
// We need to copy the document so that
|
||||
// we can add and remove the fields which
|
||||
// are relevant to the particular query.
|
||||
|
||||
doc = d.current.Copy()
|
||||
|
||||
err = d.perms(ctx, doc)
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue