diff --git a/db/check.go b/db/check.go index 18637585..7eaf6df0 100644 --- a/db/check.go +++ b/db/check.go @@ -74,7 +74,7 @@ func (d *document) grant(ctx context.Context, met method) (ok bool, err error) { // so we can check if the permissions // allow us to view this document. - tb, err := d.getTB(ctx) + tb, err := d.i.e.dbo.GetTB(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return false, err } @@ -161,7 +161,7 @@ func (d *document) allow(ctx context.Context, met method) (ok bool, err error) { // so we can check if the permissions // allow us to view this document. - tb, err := d.getTB(ctx) + tb, err := d.i.e.dbo.GetTB(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return false, err } diff --git a/db/document.go b/db/document.go index 5e271b8f..a9b905f1 100644 --- a/db/document.go +++ b/db/document.go @@ -29,9 +29,6 @@ import ( type document struct { i *iterator - ns string - db string - tb string id *sql.Thing key *keys.Thing val kvs.KV @@ -39,23 +36,6 @@ type document struct { doc *data.Doc initial *data.Doc current *data.Doc - store struct { - id int - tb bool - ev bool - fd bool - ix bool - ft bool - lv bool - } - cache struct { - tb *sql.DefineTableStatement - ev []*sql.DefineEventStatement - fd []*sql.DefineFieldStatement - ix []*sql.DefineIndexStatement - ft []*sql.DefineTableStatement - lv []*sql.LiveStatement - } } func newDocument(i *iterator, key *keys.Thing, val kvs.KV, doc *data.Doc) (d *document) { @@ -77,68 +57,11 @@ func (d *document) close() { documentPool.Put(d) } -func (d *document) clear() { - d.store.tb = false - d.store.ev = false - d.store.fd = false - d.store.ix = false - d.store.ft = false - d.store.lv = false -} - func (d *document) erase() (err error) { d.current = data.Consume(nil) return } -func (d *document) getTB(ctx context.Context) (out *sql.DefineTableStatement, err error) { - if !d.store.tb { - d.store.tb = true - d.cache.tb, err = d.i.e.dbo.GetTB(ctx, d.key.NS, d.key.DB, d.key.TB) - } - return d.cache.tb, err -} - -func (d *document) getEV(ctx context.Context) (out []*sql.DefineEventStatement, err error) { - if !d.store.ev { - d.store.ev = true - d.cache.ev, err = d.i.e.dbo.AllEV(ctx, d.key.NS, d.key.DB, d.key.TB) - } - return d.cache.ev, err -} - -func (d *document) getFD(ctx context.Context) (out []*sql.DefineFieldStatement, err error) { - if !d.store.fd { - d.store.fd = true - d.cache.fd, err = d.i.e.dbo.AllFD(ctx, d.key.NS, d.key.DB, d.key.TB) - } - return d.cache.fd, err -} - -func (d *document) getIX(ctx context.Context) (out []*sql.DefineIndexStatement, err error) { - if !d.store.ix { - d.store.ix = true - d.cache.ix, err = d.i.e.dbo.AllIX(ctx, d.key.NS, d.key.DB, d.key.TB) - } - return d.cache.ix, err -} - -func (d *document) getFT(ctx context.Context) (out []*sql.DefineTableStatement, err error) { - if !d.store.ft { - d.store.ft = true - d.cache.ft, err = d.i.e.dbo.AllFT(ctx, d.key.NS, d.key.DB, d.key.TB) - } - return d.cache.ft, err -} - -func (d *document) getLV(ctx context.Context) (out []*sql.LiveStatement, err error) { - if !d.store.lv { - d.store.lv = true - d.cache.lv, err = d.i.e.dbo.AllLV(ctx, d.key.NS, d.key.DB, d.key.TB) - } - return d.cache.lv, err -} - func (d *document) query(ctx context.Context, stm sql.Statement) (val interface{}, err error) { defer func() { @@ -265,47 +188,10 @@ func (d *document) setup(ctx context.Context) (err error) { // Finally if we are dealing with a record // which is not data from the result of a - // subquery, then generate the ID from the - // key and re-calculate any cached data. + // subquery, then generate the ID. if d.key != nil { - - // Check that the cached data for the - // current document belongs to the same - // NS, DB, and TB as the pooled document. - // If it doesn't then reset the cached data. - - if d.ns != d.key.NS { - d.ns = d.key.NS - d.clear() - } - - if d.db != d.key.DB { - d.db = d.key.DB - d.clear() - } - - if d.tb != d.key.TB { - d.tb = d.key.TB - d.clear() - } - - // Check that the cached data for the - // current document belongs to the same - // iterator as the pooled document. If - // it doesn't then reset the cached data. - - if d.i.id != d.store.id { - d.store.id = d.i.id - d.clear() - } - - // Finally, let's specify the ID of the - // current document, so we can use it - // for getting and setting data. - d.id = sql.NewThing(d.key.TB, d.key.ID) - } return @@ -332,7 +218,7 @@ func (d *document) shouldDrop(ctx context.Context) (bool, error) { // that the table should drop // writes, and if so, then return. - tb, err := d.getTB(ctx) + tb, err := d.i.e.dbo.GetTB(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return false, err } @@ -347,7 +233,7 @@ func (d *document) shouldVersn(ctx context.Context) (bool, error) { // that the table should keep // all document versions. - tb, err := d.getTB(ctx) + tb, err := d.i.e.dbo.GetTB(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return false, err } @@ -440,7 +326,7 @@ func (d *document) storeIndex(ctx context.Context) (err error) { // for this table, loop through // them, and compute the changes. - ixs, err := d.getIX(ctx) + ixs, err := d.i.e.dbo.AllIX(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } @@ -515,7 +401,7 @@ func (d *document) purgeIndex(ctx context.Context) (err error) { // for this table, loop through // them, and compute the changes. - ixs, err := d.getIX(ctx) + ixs, err := d.i.e.dbo.AllIX(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } diff --git a/db/event.go b/db/event.go index ddccd69b..7cf30780 100644 --- a/db/event.go +++ b/db/event.go @@ -47,7 +47,7 @@ func (d *document) event(ctx context.Context, met method) (err error) { // for this table, loop through // them, and compute the events. - evs, err := d.getEV(ctx) + evs, err := d.i.e.dbo.AllEV(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } diff --git a/db/lives.go b/db/lives.go index 0e0193c8..cae04fa6 100644 --- a/db/lives.go +++ b/db/lives.go @@ -42,7 +42,7 @@ func (d *document) lives(ctx context.Context, when method) (err error) { // specified for this table, and // update values which have changed. - lvs, err := d.getLV(ctx) + lvs, err := d.i.e.dbo.AllLV(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } diff --git a/db/merge.go b/db/merge.go index acb9bf46..d0ed585e 100644 --- a/db/merge.go +++ b/db/merge.go @@ -98,7 +98,7 @@ func (d *document) defFld(ctx context.Context, met method) (err error) { func (d *document) delFld(ctx context.Context, met method) (err error) { - tb, err := d.getTB(ctx) + tb, err := d.i.e.dbo.GetTB(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } @@ -109,7 +109,7 @@ func (d *document) delFld(ctx context.Context, met method) (err error) { // Get the defined fields - fds, err := d.getFD(ctx) + fds, err := d.i.e.dbo.AllFD(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } @@ -267,7 +267,7 @@ func (d *document) mrgSet(ctx context.Context, met method, expr *sql.DataExpress func (d *document) mrgFld(ctx context.Context, met method) (err error) { - fds, err := d.getFD(ctx) + fds, err := d.i.e.dbo.AllFD(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } diff --git a/db/perms.go b/db/perms.go index 0fa02219..f674719b 100644 --- a/db/perms.go +++ b/db/perms.go @@ -37,7 +37,7 @@ func (d *document) perms(ctx context.Context, doc *data.Doc) (err error) { // check if the permissions allow us // to view each field. - fds, err := d.getFD(ctx) + fds, err := d.i.e.dbo.AllFD(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err } diff --git a/db/table.go b/db/table.go index 227c4974..9b6063ec 100644 --- a/db/table.go +++ b/db/table.go @@ -51,7 +51,7 @@ func (d *document) table(ctx context.Context, when method) (err error) { // specified for this table, and // update values which have changed. - fts, err := d.getFT(ctx) + fts, err := d.i.e.dbo.AllFT(ctx, d.key.NS, d.key.DB, d.key.TB) if err != nil { return err }