From d6a44b2c7377c1ead8780f6aa6f46d2b43257ee9 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Wed, 27 Sep 2023 14:58:29 -0400 Subject: [PATCH] Remove collection.IsEmpty It adds no value in any location, and will always return false anyway. Function likely originates from a time where schemaless collections were still being considered a possibility. --- client/descriptions.go | 29 +++++++++-------------------- db/base/collection_keys.go | 14 +------------- db/fetcher/fetcher.go | 3 --- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/client/descriptions.go b/client/descriptions.go index 0b44f36b83..70e63f5da5 100644 --- a/client/descriptions.go +++ b/client/descriptions.go @@ -42,11 +42,9 @@ func (col CollectionDescription) IDString() string { // GetFieldByID searches for a field with the given ID. If such a field is found it // will return it and true, if it is not found it will return false. func (col CollectionDescription) GetFieldByID(id FieldID) (FieldDescription, bool) { - if !col.Schema.IsEmpty() { - for _, field := range col.Schema.Fields { - if field.ID == id { - return field, true - } + for _, field := range col.Schema.Fields { + if field.ID == id { + return field, true } } return FieldDescription{}, false @@ -54,11 +52,9 @@ func (col CollectionDescription) GetFieldByID(id FieldID) (FieldDescription, boo // GetRelation returns the field that supports the relation of the given name. func (col CollectionDescription) GetRelation(name string) (FieldDescription, bool) { - if !col.Schema.IsEmpty() { - for _, field := range col.Schema.Fields { - if field.RelationName == name { - return field, true - } + for _, field := range col.Schema.Fields { + if field.RelationName == name { + return field, true } } return FieldDescription{}, false @@ -91,11 +87,6 @@ type SchemaDescription struct { Fields []FieldDescription } -// IsEmpty returns true if the SchemaDescription is empty and uninitialized -func (sd SchemaDescription) IsEmpty() bool { - return len(sd.Fields) == 0 -} - // GetFieldKey returns the field ID for the given field name. func (sd SchemaDescription) GetFieldKey(fieldName string) uint32 { for _, field := range sd.Fields { @@ -108,11 +99,9 @@ func (sd SchemaDescription) GetFieldKey(fieldName string) uint32 { // GetField returns the field of the given name. func (sd SchemaDescription) GetField(name string) (FieldDescription, bool) { - if !sd.IsEmpty() { - for _, field := range sd.Fields { - if field.Name == name { - return field, true - } + for _, field := range sd.Fields { + if field.Name == name { + return field, true } } return FieldDescription{}, false diff --git a/db/base/collection_keys.go b/db/base/collection_keys.go index 0276975630..5789a3ab5a 100644 --- a/db/base/collection_keys.go +++ b/db/base/collection_keys.go @@ -42,19 +42,7 @@ func MakePrimaryIndexKeyForCRDT( case client.COMPOSITE: return MakeCollectionKey(c).WithInstanceInfo(key).WithFieldId(core.COMPOSITE_NAMESPACE), nil case client.LWW_REGISTER: - fieldKey := getFieldKey(c, key, fieldName) - return MakeCollectionKey(c).WithInstanceInfo(fieldKey), nil + return MakeCollectionKey(c).WithInstanceInfo(key).WithFieldId(fmt.Sprint(c.Schema.GetFieldKey(fieldName))), nil } return core.DataStoreKey{}, ErrInvalidCrdtType } - -func getFieldKey( - c client.CollectionDescription, - key core.DataStoreKey, - fieldName string, -) core.DataStoreKey { - if !c.Schema.IsEmpty() { - return key.WithFieldId(fmt.Sprint(c.Schema.GetFieldKey(fieldName))) - } - return key.WithFieldId(fieldName) -} diff --git a/db/fetcher/fetcher.go b/db/fetcher/fetcher.go index 34f05d4f1d..9723300f7d 100644 --- a/db/fetcher/fetcher.go +++ b/db/fetcher/fetcher.go @@ -141,9 +141,6 @@ func (df *DocumentFetcher) Init( showDeleted bool, ) error { df.txn = txn - if col.Schema.IsEmpty() { - return client.NewErrUninitializeProperty("DocumentFetcher", "Schema") - } err := df.init(col, fields, filter, docmapper, reverse) if err != nil {