Skip to content

Commit

Permalink
Pass schema in as a param to GetFieldByID
Browse files Browse the repository at this point in the history
Note: The only place that calls this only wants the field name, which long term will be available on the CollectionFieldDescription anyway.  I hope this param can be removed again soon. Additionally all properties of Schema used in that calling location will soon be on Collection itself, so the reference to Schema there is hopefully a very temporary thing too.
  • Loading branch information
AndrewSisley committed Sep 27, 2023
1 parent 0fed4bf commit 8c2717f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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) {
for _, field := range col.Schema.Fields {
func (col CollectionDescription) GetFieldByID(id FieldID, schema *SchemaDescription) (FieldDescription, bool) {
for _, field := range schema.Fields {
if field.ID == id {
return field, true
}
Expand Down
6 changes: 4 additions & 2 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,14 +1324,16 @@ func (c *collection) saveValueToMerkleCRDT(
return nil, 0, err
}

field, ok := c.Description().GetFieldByID(client.FieldID(fieldID))
schema := c.Schema()

field, ok := c.Description().GetFieldByID(client.FieldID(fieldID), &schema)
if !ok {
return nil, 0, client.NewErrFieldIndexNotExist(fieldID)
}

merkleCRDT, err := c.db.crdtFactory.InstanceWithStores(
txn,
core.NewCollectionSchemaVersionKey(c.Schema().VersionID),
core.NewCollectionSchemaVersionKey(schema.VersionID),
c.db.events.Updates,
ctype,
key,
Expand Down

0 comments on commit 8c2717f

Please sign in to comment.