Skip to content

Commit

Permalink
Take docKey string as param instead of DataStoreKey
Browse files Browse the repository at this point in the history
Is wasteful taking the whole struct (and initing one in most cases)
  • Loading branch information
AndrewSisley committed Mar 3, 2022
1 parent 73d5cc3 commit 9744349
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions db/base/maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func MakeIndexPrefixKey(col *CollectionDescription, index *IndexDescription) cor
}

// MakeIndexKey generates a key for the target dockey, using the collection/index description
func MakeIndexKey(col *CollectionDescription, index *IndexDescription, key core.DataStoreKey) core.DataStoreKey {
func MakeIndexKey(col *CollectionDescription, index *IndexDescription, docKey string) core.DataStoreKey {
return core.DataStoreKey{
CollectionId: col.IDString(),
IndexId: index.IDString(),
DocKey: key.DocKey,
DocKey: docKey,
}
}
2 changes: 1 addition & 1 deletion db/collection_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *Collection) get(ctx context.Context, txn core.Txn, key key.DocKey) (*do
}

// construct target key for DocKey
targetKey := base.MakeIndexKey(desc, index, key.Key)
targetKey := base.MakeIndexKey(desc, index, key.Key.DocKey)
// run the doc fetcher
err = df.Start(ctx, txn, core.Spans{core.NewSpan(targetKey, targetKey.PrefixEnd())})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion query/graphql/planner/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (n *selectNode) initSource(parsed *parser.Select) ([]aggregateNode, error)
spans := make(core.Spans, len(parsed.DocKeys))
for i, docKey := range parsed.DocKeys {
dockeyIndexKey := base.MakeIndexKey(&sourcePlan.info.collectionDescription,
&sourcePlan.info.collectionDescription.Indexes[0], core.DataStoreKey{DocKey: docKey})
&sourcePlan.info.collectionDescription.Indexes[0], docKey)
spans[i] = core.NewSpan(dockeyIndexKey, dockeyIndexKey.PrefixEnd())
}
origScan.Spans(spans)
Expand Down
2 changes: 1 addition & 1 deletion query/graphql/planner/type_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (n *typeJoinOne) valuesPrimary(doc map[string]interface{}) map[string]inter
// create the index key for the sub doc
slct := n.subType.(*selectTopNode).source.(*selectNode)
desc := slct.sourceInfo.collectionDescription
subKeyIndexKey := base.MakeIndexKey(&desc, &desc.Indexes[0], core.DataStoreKey{}.WithDocKey(subDocKeyStr))
subKeyIndexKey := base.MakeIndexKey(&desc, &desc.Indexes[0], subDocKeyStr)

n.spans = core.Spans{} // reset span
n.spans = append(n.spans, core.NewSpan(subKeyIndexKey, subKeyIndexKey.PrefixEnd()))
Expand Down
2 changes: 1 addition & 1 deletion query/graphql/planner/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (n *updateNode) Values() map[string]interface{} {
// create a new span with the updateDoc._key
docKeyStr := updatedDoc["_key"].(string)
desc := n.collection.Description()
updatedDocKeyIndex := base.MakeIndexKey(&desc, &desc.Indexes[0], core.DataStoreKey{}.WithDocKey(docKeyStr))
updatedDocKeyIndex := base.MakeIndexKey(&desc, &desc.Indexes[0], docKeyStr)
spans := core.Spans{core.NewSpan(updatedDocKeyIndex, updatedDocKeyIndex.PrefixEnd())}

n.results.Spans(spans)
Expand Down

0 comments on commit 9744349

Please sign in to comment.