From 32be1e06409767b50720bb141b82dc8174f69021 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Wed, 27 Nov 2024 12:53:34 -0500 Subject: [PATCH] WIP - Remove unused reverse prop It hasn't been used in 3 years, it can die and come back if/when needed. --- internal/db/collection_get.go | 2 +- internal/db/collection_index.go | 1 - internal/db/fetcher/fetcher.go | 25 ++++--------------------- internal/db/fetcher/indexer.go | 2 -- internal/db/fetcher/mocks/fetcher.go | 21 ++++++++++----------- internal/db/fetcher/mocks/utils.go | 1 - internal/db/fetcher/versioned.go | 2 -- internal/db/indexed_docs_test.go | 8 +------- internal/lens/fetcher.go | 2 -- internal/planner/scan.go | 2 -- 10 files changed, 16 insertions(+), 50 deletions(-) diff --git a/internal/db/collection_get.go b/internal/db/collection_get.go index 8360cc0915..c67f30e9b5 100644 --- a/internal/db/collection_get.go +++ b/internal/db/collection_get.go @@ -63,7 +63,7 @@ func (c *collection) get( // create a new document fetcher df := c.newFetcher() // initialize it with the primary index - err := df.Init(ctx, identity.FromContext(ctx), txn, c.db.acp, c, fields, nil, nil, false, showDeleted) + err := df.Init(ctx, identity.FromContext(ctx), txn, c.db.acp, c, fields, nil, nil, showDeleted) if err != nil { _ = df.Close() return nil, err diff --git a/internal/db/collection_index.go b/internal/db/collection_index.go index 3c5da18c58..a781683943 100644 --- a/internal/db/collection_index.go +++ b/internal/db/collection_index.go @@ -310,7 +310,6 @@ func (c *collection) iterateAllDocs( nil, nil, false, - false, ) if err != nil { return errors.Join(err, df.Close()) diff --git a/internal/db/fetcher/fetcher.go b/internal/db/fetcher/fetcher.go index 422de57ad7..877cbfa7c8 100644 --- a/internal/db/fetcher/fetcher.go +++ b/internal/db/fetcher/fetcher.go @@ -70,7 +70,6 @@ type Fetcher interface { fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, - reverse bool, showDeleted bool, ) error Start(ctx context.Context, prefixes ...keys.Walkable) error @@ -95,7 +94,6 @@ type DocumentFetcher struct { passedPermissionCheck bool // have valid permission to access col client.Collection - reverse bool deletedDocs bool txn datastore.Txn @@ -156,12 +154,11 @@ func (df *DocumentFetcher) Init( fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, - reverse bool, showDeleted bool, ) error { df.txn = txn - err := df.init(identity, acp, col, fields, filter, docmapper, reverse) + err := df.init(identity, acp, col, fields, filter, docmapper) if err != nil { return err } @@ -171,7 +168,7 @@ func (df *DocumentFetcher) Init( df.deletedDocFetcher = new(DocumentFetcher) df.deletedDocFetcher.txn = txn } - return df.deletedDocFetcher.init(identity, acp, col, fields, filter, docmapper, reverse) + return df.deletedDocFetcher.init(identity, acp, col, fields, filter, docmapper) } return nil @@ -184,12 +181,10 @@ func (df *DocumentFetcher) init( fields []client.FieldDefinition, filter *mapper.Filter, docMapper *core.DocumentMapping, - reverse bool, ) error { df.identity = identity df.acp = acp df.col = col - df.reverse = reverse df.initialized = true df.filter = filter df.isReadingDocument = false @@ -300,20 +295,10 @@ func (df *DocumentFetcher) start(ctx context.Context, prefixes []keys.Walkable, return strings.Compare(a.ToString(), b.ToString()) }) - if df.reverse { - for i, j := 0, len(valuePrefixes)-1; i < j; i, j = i+1, j-1 { - valuePrefixes[i], valuePrefixes[j] = valuePrefixes[j], valuePrefixes[i] - } - } df.prefixes = valuePrefixes } df.curPrefixIndex = -1 - - if df.reverse { - df.order = []dsq.Order{dsq.OrderByKeyDescending{}} - } else { - df.order = []dsq.Order{dsq.OrderByKey{}} - } + df.order = []dsq.Order{dsq.OrderByKey{}} _, err := df.startNextPrefix(ctx) return err @@ -571,9 +556,7 @@ func (df *DocumentFetcher) FetchNext(ctx context.Context) (EncodedDocument, Exec if ddf != nil { // If we've reached the end of the deleted docs, we can skip to getting the next active docs. if !ddf.kvEnd { - if df.kvEnd || - (df.reverse && ddf.kv.Key.DocID > df.kv.Key.DocID) || - (!df.reverse && ddf.kv.Key.DocID < df.kv.Key.DocID) { + if df.kvEnd || ddf.kv.Key.DocID < df.kv.Key.DocID { encdoc, execInfo, err := ddf.FetchNext(ctx) if err != nil { diff --git a/internal/db/fetcher/indexer.go b/internal/db/fetcher/indexer.go index 71881a31ab..12fd866cb6 100644 --- a/internal/db/fetcher/indexer.go +++ b/internal/db/fetcher/indexer.go @@ -65,7 +65,6 @@ func (f *IndexFetcher) Init( fields []client.FieldDefinition, filter *mapper.Filter, docMapper *core.DocumentMapping, - reverse bool, showDeleted bool, ) error { f.resetState() @@ -118,7 +117,6 @@ outer: filter, f.mapping, false, - false, ) } diff --git a/internal/db/fetcher/mocks/fetcher.go b/internal/db/fetcher/mocks/fetcher.go index a75d1c8ba9..723403723f 100644 --- a/internal/db/fetcher/mocks/fetcher.go +++ b/internal/db/fetcher/mocks/fetcher.go @@ -148,17 +148,17 @@ func (_c *Fetcher_FetchNext_Call) RunAndReturn(run func(context.Context) (fetche return _c } -// Init provides a mock function with given fields: ctx, _a1, txn, _a3, col, fields, filter, docmapper, reverse, showDeleted -func (_m *Fetcher) Init(ctx context.Context, _a1 immutable.Option[identity.Identity], txn datastore.Txn, _a3 immutable.Option[acp.ACP], col client.Collection, fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, reverse bool, showDeleted bool) error { - ret := _m.Called(ctx, _a1, txn, _a3, col, fields, filter, docmapper, reverse, showDeleted) +// Init provides a mock function with given fields: ctx, _a1, txn, _a3, col, fields, filter, docmapper, showDeleted +func (_m *Fetcher) Init(ctx context.Context, _a1 immutable.Option[identity.Identity], txn datastore.Txn, _a3 immutable.Option[acp.ACP], col client.Collection, fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, showDeleted bool) error { + ret := _m.Called(ctx, _a1, txn, _a3, col, fields, filter, docmapper, showDeleted) if len(ret) == 0 { panic("no return value specified for Init") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, immutable.Option[identity.Identity], datastore.Txn, immutable.Option[acp.ACP], client.Collection, []client.FieldDefinition, *mapper.Filter, *core.DocumentMapping, bool, bool) error); ok { - r0 = rf(ctx, _a1, txn, _a3, col, fields, filter, docmapper, reverse, showDeleted) + if rf, ok := ret.Get(0).(func(context.Context, immutable.Option[identity.Identity], datastore.Txn, immutable.Option[acp.ACP], client.Collection, []client.FieldDefinition, *mapper.Filter, *core.DocumentMapping, bool) error); ok { + r0 = rf(ctx, _a1, txn, _a3, col, fields, filter, docmapper, showDeleted) } else { r0 = ret.Error(0) } @@ -180,15 +180,14 @@ type Fetcher_Init_Call struct { // - fields []client.FieldDefinition // - filter *mapper.Filter // - docmapper *core.DocumentMapping -// - reverse bool // - showDeleted bool -func (_e *Fetcher_Expecter) Init(ctx interface{}, _a1 interface{}, txn interface{}, _a3 interface{}, col interface{}, fields interface{}, filter interface{}, docmapper interface{}, reverse interface{}, showDeleted interface{}) *Fetcher_Init_Call { - return &Fetcher_Init_Call{Call: _e.mock.On("Init", ctx, _a1, txn, _a3, col, fields, filter, docmapper, reverse, showDeleted)} +func (_e *Fetcher_Expecter) Init(ctx interface{}, _a1 interface{}, txn interface{}, _a3 interface{}, col interface{}, fields interface{}, filter interface{}, docmapper interface{}, showDeleted interface{}) *Fetcher_Init_Call { + return &Fetcher_Init_Call{Call: _e.mock.On("Init", ctx, _a1, txn, _a3, col, fields, filter, docmapper, showDeleted)} } -func (_c *Fetcher_Init_Call) Run(run func(ctx context.Context, _a1 immutable.Option[identity.Identity], txn datastore.Txn, _a3 immutable.Option[acp.ACP], col client.Collection, fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, reverse bool, showDeleted bool)) *Fetcher_Init_Call { +func (_c *Fetcher_Init_Call) Run(run func(ctx context.Context, _a1 immutable.Option[identity.Identity], txn datastore.Txn, _a3 immutable.Option[acp.ACP], col client.Collection, fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, showDeleted bool)) *Fetcher_Init_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(immutable.Option[identity.Identity]), args[2].(datastore.Txn), args[3].(immutable.Option[acp.ACP]), args[4].(client.Collection), args[5].([]client.FieldDefinition), args[6].(*mapper.Filter), args[7].(*core.DocumentMapping), args[8].(bool), args[9].(bool)) + run(args[0].(context.Context), args[1].(immutable.Option[identity.Identity]), args[2].(datastore.Txn), args[3].(immutable.Option[acp.ACP]), args[4].(client.Collection), args[5].([]client.FieldDefinition), args[6].(*mapper.Filter), args[7].(*core.DocumentMapping), args[8].(bool)) }) return _c } @@ -198,7 +197,7 @@ func (_c *Fetcher_Init_Call) Return(_a0 error) *Fetcher_Init_Call { return _c } -func (_c *Fetcher_Init_Call) RunAndReturn(run func(context.Context, immutable.Option[identity.Identity], datastore.Txn, immutable.Option[acp.ACP], client.Collection, []client.FieldDefinition, *mapper.Filter, *core.DocumentMapping, bool, bool) error) *Fetcher_Init_Call { +func (_c *Fetcher_Init_Call) RunAndReturn(run func(context.Context, immutable.Option[identity.Identity], datastore.Txn, immutable.Option[acp.ACP], client.Collection, []client.FieldDefinition, *mapper.Filter, *core.DocumentMapping, bool) error) *Fetcher_Init_Call { _c.Call.Return(run) return _c } diff --git a/internal/db/fetcher/mocks/utils.go b/internal/db/fetcher/mocks/utils.go index 524c46fc9e..d12f4fdd98 100644 --- a/internal/db/fetcher/mocks/utils.go +++ b/internal/db/fetcher/mocks/utils.go @@ -28,7 +28,6 @@ func NewStubbedFetcher(t *testing.T) *Fetcher { mock.Anything, mock.Anything, mock.Anything, - mock.Anything, ).Maybe().Return(nil) f.EXPECT().Start(mock.Anything, mock.Anything).Maybe().Return(nil) f.EXPECT().FetchNext(mock.Anything).Maybe().Return(nil, nil) diff --git a/internal/db/fetcher/versioned.go b/internal/db/fetcher/versioned.go index c362a9c9b3..6abb42aab2 100644 --- a/internal/db/fetcher/versioned.go +++ b/internal/db/fetcher/versioned.go @@ -106,7 +106,6 @@ func (vf *VersionedFetcher) Init( fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, - reverse bool, showDeleted bool, ) error { vf.acp = acp @@ -141,7 +140,6 @@ func (vf *VersionedFetcher) Init( fields, filter, docmapper, - reverse, showDeleted, ) } diff --git a/internal/db/indexed_docs_test.go b/internal/db/indexed_docs_test.go index 2c6ce0af53..6ec3b92ce7 100644 --- a/internal/db/indexed_docs_test.go +++ b/internal/db/indexed_docs_test.go @@ -606,7 +606,6 @@ func TestNonUniqueCreate_IfUponIndexingExistingDocsFetcherFails_ReturnError(t *t mock.Anything, mock.Anything, mock.Anything, - mock.Anything, ).Unset() f.EXPECT().Init( mock.Anything, @@ -618,7 +617,6 @@ func TestNonUniqueCreate_IfUponIndexingExistingDocsFetcherFails_ReturnError(t *t mock.Anything, mock.Anything, mock.Anything, - mock.Anything, ).Return(testError) f.EXPECT().Close().Unset() f.EXPECT().Close().Return(nil) @@ -839,7 +837,6 @@ func TestNonUniqueUpdate_IfFetcherFails_ReturnError(t *testing.T) { mock.Anything, mock.Anything, mock.Anything, - mock.Anything, ).Unset() f.EXPECT().Init( mock.Anything, @@ -851,7 +848,6 @@ func TestNonUniqueUpdate_IfFetcherFails_ReturnError(t *testing.T) { mock.Anything, mock.Anything, mock.Anything, - mock.Anything, ).Return(testError) f.EXPECT().Close().Unset() f.EXPECT().Close().Return(nil) @@ -960,7 +956,6 @@ func TestNonUniqueUpdate_ShouldPassToFetcherOnlyRelevantFields(t *testing.T) { mock.Anything, mock.Anything, mock.Anything, - mock.Anything, ).Unset() f.EXPECT().Init( mock.Anything, @@ -972,7 +967,6 @@ func TestNonUniqueUpdate_ShouldPassToFetcherOnlyRelevantFields(t *testing.T) { mock.Anything, mock.Anything, mock.Anything, - mock.Anything, ). RunAndReturn(func( ctx context.Context, @@ -983,7 +977,7 @@ func TestNonUniqueUpdate_ShouldPassToFetcherOnlyRelevantFields(t *testing.T) { fields []client.FieldDefinition, filter *mapper.Filter, mapping *core.DocumentMapping, - reverse, showDeleted bool, + showDeleted bool, ) error { require.Equal(t, 2, len(fields)) require.ElementsMatch(t, diff --git a/internal/lens/fetcher.go b/internal/lens/fetcher.go index 1729aecdb4..e5c1f3f8e5 100644 --- a/internal/lens/fetcher.go +++ b/internal/lens/fetcher.go @@ -70,7 +70,6 @@ func (f *lensedFetcher) Init( fields []client.FieldDefinition, filter *mapper.Filter, docmapper *core.DocumentMapping, - reverse bool, showDeleted bool, ) error { f.col = col @@ -122,7 +121,6 @@ historyLoop: innerFetcherFields, filter, docmapper, - reverse, showDeleted, ) } diff --git a/internal/planner/scan.go b/internal/planner/scan.go index eed370d0ae..4f577519a3 100644 --- a/internal/planner/scan.go +++ b/internal/planner/scan.go @@ -47,7 +47,6 @@ type scanNode struct { showDeleted bool prefixes []keys.Walkable - reverse bool filter *mapper.Filter slct *mapper.Select @@ -72,7 +71,6 @@ func (n *scanNode) Init() error { n.fields, n.filter, n.slct.DocumentMapping, - n.reverse, n.showDeleted, ); err != nil { return err