Skip to content

Commit

Permalink
WIP - Remove unused return param from col.save
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Oct 31, 2024
1 parent 7c7c030 commit 31b5d06
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions internal/db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"strconv"
"strings"

"github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
Expand Down Expand Up @@ -467,7 +466,7 @@ func (c *collection) create(
}

// write data to DB via MerkleClock/CRDT
_, err = c.save(ctx, doc, true)
err = c.save(ctx, doc, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -535,7 +534,7 @@ func (c *collection) update(
return client.ErrDocumentNotFoundOrNotAuthorized
}

_, err = c.save(ctx, doc, false)
err = c.save(ctx, doc, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -605,15 +604,15 @@ func (c *collection) save(
ctx context.Context,
doc *client.Document,
isCreate bool,
) (cid.Cid, error) {
) error {
if err := c.validateEncryptedFields(ctx); err != nil {
return cid.Undef, err
return err
}

if !isCreate {
err := c.updateIndexedDoc(ctx, doc)
if err != nil {
return cid.Undef, err
return err
}
}
txn := mustGetContextTxn(ctx)
Expand All @@ -637,19 +636,19 @@ func (c *collection) save(
for k, v := range doc.Fields() {
val, err := doc.GetValueWithField(v)
if err != nil {
return cid.Undef, err
return err
}

if val.IsDirty() {
fieldKey, fieldExists := c.tryGetFieldKey(primaryKey, k)

if !fieldExists {
return cid.Undef, client.NewErrFieldNotExist(k)
return client.NewErrFieldNotExist(k)
}

fieldDescription, valid := c.Definition().GetFieldByName(k)
if !valid {
return cid.Undef, client.NewErrFieldNotExist(k)
return client.NewErrFieldNotExist(k)
}

// by default the type will have been set to LWW_REGISTER. We need to ensure
Expand All @@ -663,7 +662,7 @@ func (c *collection) save(
val.Value(),
)
if err != nil {
return cid.Undef, err
return err
}

merkleCRDT, err := merklecrdt.InstanceWithStore(
Expand All @@ -675,12 +674,12 @@ func (c *collection) save(
fieldDescription.Name,
)
if err != nil {
return cid.Undef, err
return err
}

link, _, err := merkleCRDT.Save(ctx, merklecrdt.NewDocField(primaryKey.DocID, k, val))
if err != nil {
return cid.Undef, err
return err
}

links = append(links, coreblock.NewDAGLink(k, link))
Expand All @@ -694,7 +693,7 @@ func (c *collection) save(
client.Active,
)
if err != nil {
return cid.Undef, err
return err
}

// publish an update event when the txn succeeds
Expand All @@ -712,7 +711,7 @@ func (c *collection) save(
doc.SetHead(link.Cid)
})

return link.Cid, nil
return nil
}

func (c *collection) validateOneToOneLinkDoesntAlreadyExist(
Expand Down

0 comments on commit 31b5d06

Please sign in to comment.