diff --git a/internal/db/fetcher/document.go b/internal/db/fetcher/document.go index 8f4e69cf76..fe650499fb 100644 --- a/internal/db/fetcher/document.go +++ b/internal/db/fetcher/document.go @@ -23,10 +23,10 @@ import ( "github.com/sourcenetwork/defradb/internal/keys" ) -// document is the type responsible for fetching documents from the datastore. +// documentFetcher is the type responsible for fetching documents from the datastore. // // It does not filter the data in any way. -type document struct { +type documentFetcher struct { // The set of fields to fetch, mapped by field ID. fieldsByID map[uint32]client.FieldDefinition // The status to assign fetched documents. @@ -46,7 +46,7 @@ type document struct { nextKV immutable.Option[keyValue] } -var _ fetcher = (*document)(nil) +var _ fetcher = (*documentFetcher)(nil) func newDocumentFetcher( ctx context.Context, @@ -55,7 +55,7 @@ func newDocumentFetcher( prefix keys.DataStoreKey, status client.DocumentStatus, execInfo *ExecInfo, -) (*document, error) { +) (*documentFetcher, error) { if status == client.Active { prefix = prefix.WithValueFlag() } else if status == client.Deleted { @@ -67,7 +67,7 @@ func newDocumentFetcher( return nil, err } - return &document{ + return &documentFetcher{ fieldsByID: fieldsByID, kvResultsIter: kvResultsIter, status: status, @@ -81,7 +81,7 @@ type keyValue struct { Value []byte } -func (f *document) NextDoc() (immutable.Option[string], error) { +func (f *documentFetcher) NextDoc() (immutable.Option[string], error) { if f.nextKV.HasValue() { docID := f.nextKV.Value().Key.DocID f.currentKV = f.nextKV.Value() @@ -120,7 +120,7 @@ func (f *document) NextDoc() (immutable.Option[string], error) { return immutable.Some(f.currentKV.Key.DocID), nil } -func (f *document) GetFields() (immutable.Option[EncodedDocument], error) { +func (f *documentFetcher) GetFields() (immutable.Option[EncodedDocument], error) { doc := encodedDocument{} doc.id = []byte(f.currentKV.Key.DocID) doc.status = f.status @@ -161,7 +161,7 @@ func (f *document) GetFields() (immutable.Option[EncodedDocument], error) { return immutable.Some[EncodedDocument](&doc), nil } -func (f *document) appendKv(doc *encodedDocument, kv keyValue) error { +func (f *documentFetcher) appendKv(doc *encodedDocument, kv keyValue) error { if kv.Key.FieldID == keys.DATASTORE_DOC_VERSION_FIELD_ID { doc.schemaVersionID = string(kv.Value) return nil @@ -192,6 +192,6 @@ func (f *document) appendKv(doc *encodedDocument, kv keyValue) error { return nil } -func (f *document) Close() error { +func (f *documentFetcher) Close() error { return f.kvResultsIter.Close() } diff --git a/internal/db/fetcher/filtered.go b/internal/db/fetcher/filtered.go index 511e93ca14..cdd78e3f23 100644 --- a/internal/db/fetcher/filtered.go +++ b/internal/db/fetcher/filtered.go @@ -17,34 +17,34 @@ import ( "github.com/sourcenetwork/defradb/internal/planner/mapper" ) -// filtered fetcher is responsible for the filtering documents based on the provided +// filteredFetcher fetcher is responsible for the filtering documents based on the provided // conditions. -type filtered struct { +type filteredFetcher struct { filter *mapper.Filter mapping *core.DocumentMapping fetcher fetcher } -var _ fetcher = (*filtered)(nil) +var _ fetcher = (*filteredFetcher)(nil) func newFilteredFetcher( filter *mapper.Filter, mapping *core.DocumentMapping, fetcher fetcher, -) *filtered { - return &filtered{ +) *filteredFetcher { + return &filteredFetcher{ filter: filter, mapping: mapping, fetcher: fetcher, } } -func (f *filtered) NextDoc() (immutable.Option[string], error) { +func (f *filteredFetcher) NextDoc() (immutable.Option[string], error) { return f.fetcher.NextDoc() } -func (f *filtered) GetFields() (immutable.Option[EncodedDocument], error) { +func (f *filteredFetcher) GetFields() (immutable.Option[EncodedDocument], error) { doc, err := f.fetcher.GetFields() if err != nil { return immutable.None[EncodedDocument](), err @@ -71,6 +71,6 @@ func (f *filtered) GetFields() (immutable.Option[EncodedDocument], error) { return doc, nil } -func (f *filtered) Close() error { +func (f *filteredFetcher) Close() error { return f.fetcher.Close() } diff --git a/internal/db/fetcher/multi.go b/internal/db/fetcher/multi.go index 4d807c3259..d896568954 100644 --- a/internal/db/fetcher/multi.go +++ b/internal/db/fetcher/multi.go @@ -16,10 +16,10 @@ import ( "github.com/sourcenetwork/immutable" ) -// multi is a fetcher that orchastrates the fetching of documents via multiple child fetchers. +// multiFetcher is a fetcher that orchastrates the fetching of documents via multiple child fetchers. // // The documents are yielded ordered by docID independently of which child fetcher they are sourced from. -type multi struct { +type multiFetcher struct { children []fetcherDocID // The index of the fetcher that last returned an item from `NextDoc`. @@ -28,11 +28,11 @@ type multi struct { currentFetcherIndex int } -var _ fetcher = (*multi)(nil) +var _ fetcher = (*multiFetcher)(nil) func newMultiFetcher( children ...fetcher, -) *multi { +) *multiFetcher { fetcherDocIDs := make([]fetcherDocID, len(children)) for i, fetcher := range children { @@ -41,7 +41,7 @@ func newMultiFetcher( } } - return &multi{ + return &multiFetcher{ children: fetcherDocIDs, } } @@ -54,7 +54,7 @@ type fetcherDocID struct { docID immutable.Option[string] } -func (f *multi) NextDoc() (immutable.Option[string], error) { +func (f *multiFetcher) NextDoc() (immutable.Option[string], error) { selectedFetcherIndex := -1 var selectedDocID immutable.Option[string] @@ -93,7 +93,7 @@ func (f *multi) NextDoc() (immutable.Option[string], error) { return selectedDocID, nil } -func (f *multi) GetFields() (immutable.Option[EncodedDocument], error) { +func (f *multiFetcher) GetFields() (immutable.Option[EncodedDocument], error) { doc, err := f.children[f.currentFetcherIndex].fetcher.GetFields() if err != nil { return immutable.None[EncodedDocument](), err @@ -104,7 +104,7 @@ func (f *multi) GetFields() (immutable.Option[EncodedDocument], error) { return doc, nil } -func (f *multi) Close() error { +func (f *multiFetcher) Close() error { errs := []error{} for _, child := range f.children { err := child.fetcher.Close() diff --git a/internal/db/fetcher/permissioned.go b/internal/db/fetcher/permissioned.go index 16165e45db..fc9ee52495 100644 --- a/internal/db/fetcher/permissioned.go +++ b/internal/db/fetcher/permissioned.go @@ -21,8 +21,8 @@ import ( "github.com/sourcenetwork/defradb/internal/db/permission" ) -// permissioned fetcher applies access control based filtering to documents fetched. -type permissioned struct { +// permissionedFetcher fetcher applies access control based filtering to documents fetched. +type permissionedFetcher struct { ctx context.Context identity immutable.Option[acpIdentity.Identity] @@ -32,7 +32,7 @@ type permissioned struct { fetcher fetcher } -var _ fetcher = (*permissioned)(nil) +var _ fetcher = (*permissionedFetcher)(nil) func newPermissionedFetcher( ctx context.Context, @@ -40,8 +40,8 @@ func newPermissionedFetcher( acp acp.ACP, col client.Collection, fetcher fetcher, -) *permissioned { - return &permissioned{ +) *permissionedFetcher { + return &permissionedFetcher{ ctx: ctx, identity: identity, acp: acp, @@ -50,7 +50,7 @@ func newPermissionedFetcher( } } -func (f *permissioned) NextDoc() (immutable.Option[string], error) { +func (f *permissionedFetcher) NextDoc() (immutable.Option[string], error) { docID, err := f.fetcher.NextDoc() if err != nil { return immutable.None[string](), err @@ -79,10 +79,10 @@ func (f *permissioned) NextDoc() (immutable.Option[string], error) { return docID, nil } -func (f *permissioned) GetFields() (immutable.Option[EncodedDocument], error) { +func (f *permissionedFetcher) GetFields() (immutable.Option[EncodedDocument], error) { return f.fetcher.GetFields() } -func (f *permissioned) Close() error { +func (f *permissionedFetcher) Close() error { return f.fetcher.Close() } diff --git a/internal/db/fetcher/prefix.go b/internal/db/fetcher/prefix.go index d494384670..277db2e4e8 100644 --- a/internal/db/fetcher/prefix.go +++ b/internal/db/fetcher/prefix.go @@ -24,10 +24,10 @@ import ( "github.com/sourcenetwork/defradb/internal/keys" ) -// prefix is a fetcher type responsible for iterating through multiple prefixes. +// prefixFetcher is a fetcher type responsible for iterating through multiple prefixes. // // It manages the document fetcher instances that will do the actual scanning. -type prefix struct { +type prefixFetcher struct { // The prefixes that this prefix fetcher must fetch from. prefixes []keys.DataStoreKey // The Iterator this prefix fetcher will use to scan. @@ -36,7 +36,7 @@ type prefix struct { // The index of the current prefix being fetched. currentPrefix int // The child document fetcher, specific to the current prefix. - fetcher *document + fetcher *documentFetcher // The below properties are only held here in order to pass them on to the next // child fetcher instance. @@ -46,7 +46,7 @@ type prefix struct { execInfo *ExecInfo } -var _ fetcher = (*prefix)(nil) +var _ fetcher = (*prefixFetcher)(nil) func newPrefixFetcher( ctx context.Context, @@ -56,7 +56,7 @@ func newPrefixFetcher( fieldsByID map[uint32]client.FieldDefinition, status client.DocumentStatus, execInfo *ExecInfo, -) (*prefix, error) { +) (*prefixFetcher, error) { kvIter, err := txn.Datastore().GetIterator(dsq.Query{}) if err != nil { return nil, err @@ -92,7 +92,7 @@ func newPrefixFetcher( return nil, err } - return &prefix{ + return &prefixFetcher{ kvIter: kvIter, prefixes: prefixes, ctx: ctx, @@ -103,7 +103,7 @@ func newPrefixFetcher( }, nil } -func (f *prefix) NextDoc() (immutable.Option[string], error) { +func (f *prefixFetcher) NextDoc() (immutable.Option[string], error) { docID, err := f.fetcher.NextDoc() if err != nil { return immutable.None[string](), err @@ -133,10 +133,10 @@ func (f *prefix) NextDoc() (immutable.Option[string], error) { return docID, nil } -func (f *prefix) GetFields() (immutable.Option[EncodedDocument], error) { +func (f *prefixFetcher) GetFields() (immutable.Option[EncodedDocument], error) { return f.fetcher.GetFields() } -func (f *prefix) Close() error { +func (f *prefixFetcher) Close() error { return f.kvIter.Close() } diff --git a/internal/db/fetcher/wrapper.go b/internal/db/fetcher/wrapper.go index 298f7cdbfc..507158153a 100644 --- a/internal/db/fetcher/wrapper.go +++ b/internal/db/fetcher/wrapper.go @@ -25,9 +25,9 @@ import ( "github.com/sourcenetwork/defradb/internal/request/graphql/parser" ) -// wrapper is a fetcher type that bridges between the existing [Fetcher] interface +// wrappingFetcher is a fetcher type that bridges between the existing [Fetcher] interface // and the newer [fetcher] interface. -type wrapper struct { +type wrappingFetcher struct { fetcher fetcher execInfo *ExecInfo @@ -43,13 +43,13 @@ type wrapper struct { showDeleted bool } -var _ Fetcher = (*wrapper)(nil) +var _ Fetcher = (*wrappingFetcher)(nil) func NewDocumentFetcher() Fetcher { - return &wrapper{} + return &wrappingFetcher{} } -func (f *wrapper) Init( +func (f *wrappingFetcher) Init( ctx context.Context, identity immutable.Option[acpIdentity.Identity], txn datastore.Txn, @@ -72,7 +72,7 @@ func (f *wrapper) Init( return nil } -func (f *wrapper) Start(ctx context.Context, prefixes ...keys.Walkable) error { +func (f *wrappingFetcher) Start(ctx context.Context, prefixes ...keys.Walkable) error { err := f.Close() if err != nil { return err @@ -147,7 +147,7 @@ func (f *wrapper) Start(ctx context.Context, prefixes ...keys.Walkable) error { return nil } -func (f *wrapper) FetchNext(ctx context.Context) (EncodedDocument, ExecInfo, error) { +func (f *wrappingFetcher) FetchNext(ctx context.Context) (EncodedDocument, ExecInfo, error) { docID, err := f.fetcher.NextDoc() if err != nil { return nil, ExecInfo{}, err @@ -175,7 +175,7 @@ func (f *wrapper) FetchNext(ctx context.Context) (EncodedDocument, ExecInfo, err return doc.Value(), execInfo, nil } -func (f *wrapper) Close() error { +func (f *wrappingFetcher) Close() error { if f.fetcher != nil { return f.fetcher.Close() }