Skip to content

Commit

Permalink
refactor: Remove GetPrimaryIndexDocKey from collection interface (sou…
Browse files Browse the repository at this point in the history
…rcenetwork#279)

* Remove GetPrimaryIndexDocKey from collection interface

No real reason for this to be on here, and it exposes internal types

* Remove commented out code
  • Loading branch information
AndrewSisley authored Mar 10, 2022
1 parent 57375e4 commit 55696f6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion client/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ type Collection interface {

WithTxn(core.Txn) Collection

GetPrimaryIndexDocKey(core.DataStoreKey) core.DataStoreKey
GetAllDocKeys(ctx context.Context) (<-chan DocKeysResult, error)
}

Expand Down
13 changes: 12 additions & 1 deletion db/base/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (col CollectionDescription) GetField(name string) (FieldDescription, bool)
return FieldDescription{}, false
}

func (c CollectionDescription) GetPrimaryIndex() IndexDescription {
return c.Indexes[0]
}

func (c CollectionDescription) getIndexDocKey(key core.DataStoreKey, indexID uint32) core.DataStoreKey {
return core.DataStoreKey{
CollectionId: c.IDString(),
Expand All @@ -66,7 +70,7 @@ func (c CollectionDescription) getIndexDocKey(key core.DataStoreKey, indexID uin
}

func (c CollectionDescription) getPrimaryIndexDocKey(key core.DataStoreKey) core.DataStoreKey {
return c.getIndexDocKey(key, c.Indexes[0].ID)
return c.getIndexDocKey(key, c.GetPrimaryIndex().ID)
}

func (c CollectionDescription) getFieldKey(key core.DataStoreKey, fieldName string) core.DataStoreKey {
Expand All @@ -87,6 +91,13 @@ func (c CollectionDescription) GetPrimaryIndexDocKeyForCRDT(ctype core.CType, ke
return core.DataStoreKey{}, errors.New("Invalid CRDT type")
}

func (c CollectionDescription) GetPrimaryIndexDocKey(key core.DataStoreKey) core.DataStoreKey {
return core.DataStoreKey{
CollectionId: fmt.Sprint(c.ID),
IndexId: fmt.Sprint(c.GetPrimaryIndex().ID),
}.WithInstanceInfo(key)
}

// IndexDescription describes an Index on a Collection
// and its associated metadata.
type IndexDescription struct {
Expand Down
4 changes: 0 additions & 4 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,6 @@ func (c *Collection) commitImplicitTxn(ctx context.Context, txn core.Txn) error
return nil
}

func (c *Collection) GetPrimaryIndexDocKey(key core.DataStoreKey) core.DataStoreKey {
return c.getPrimaryIndexDocKey(key)
}

func (c *Collection) getPrimaryIndexDocKey(key core.DataStoreKey) core.DataStoreKey {
return core.DataStoreKey{
CollectionId: fmt.Sprint(c.colID),
Expand Down
8 changes: 0 additions & 8 deletions db/fetcher/versioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,3 @@ func NewVersionedSpan(dockey core.DataStoreKey, version cid.Cid) core.Spans {
// Todo: Dont abuse DataStoreKey for version cid!
return core.Spans{core.NewSpan(dockey, core.DataStoreKey{DocKey: version.String()})}
}

// func createMerkleCRDT(ctype core.CType, key ds.Key, store core.MultiStore) (crdt.MerkleCRDT, error) {
// key := vf.col.GetPrimaryIndexDocKey(vf.key.Key).ChildString(core.COMPOSITE_ID)
// compCRDT, err = crdt.DefaultFactory.InstanceWithStores(vf.store, core.COMPOSITE, key)
// if err != nil {
// return err
// }
// }
4 changes: 2 additions & 2 deletions net/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ func initCRDTForType(ctx context.Context, txn core.MultiStore, col client.Collec
var ctype core.CType
if field == "" { // empty field name implies composite type
ctype = core.COMPOSITE
key = col.GetPrimaryIndexDocKey(docKey).WithFieldId(core.COMPOSITE_NAMESPACE)
key = col.Description().GetPrimaryIndexDocKey(docKey).WithFieldId(core.COMPOSITE_NAMESPACE)
} else {
fd, ok := col.Description().GetField(field)
if !ok {
return nil, fmt.Errorf("Couldn't find field %s for doc %s", field, docKey)
}
ctype = fd.Typ
fieldID := fd.ID.String()
key = col.GetPrimaryIndexDocKey(docKey).WithFieldId(fieldID)
key = col.Description().GetPrimaryIndexDocKey(docKey).WithFieldId(fieldID)
}
log.Debug(ctx, "Got CRDT Type", logging.NewKV("CType", ctype), logging.NewKV("Field", field))
return crdt.DefaultFactory.InstanceWithStores(txn, col.SchemaID(), nil, ctype, key)
Expand Down

0 comments on commit 55696f6

Please sign in to comment.