Skip to content

Commit

Permalink
Remove collection.IsEmpty
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AndrewSisley committed Sep 27, 2023
1 parent 2c862ac commit d6a44b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
29 changes: 9 additions & 20 deletions client/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,19 @@ 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
}

// 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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
14 changes: 1 addition & 13 deletions db/base/collection_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 0 additions & 3 deletions db/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d6a44b2

Please sign in to comment.