Open
Conversation
alanshaw
approved these changes
Feb 23, 2026
volmedo
approved these changes
Feb 23, 2026
Member
volmedo
left a comment
There was a problem hiding this comment.
LGTM, just a couple nits if you wanna take a look.
| return shards, nil | ||
| } | ||
|
|
||
| func (r *Repo) ForEachNodeInIndex(ctx context.Context, indexID id.IndexID, yield func(shardDigest multihash.Multihash, nodeCID cid.Cid, nodeSize uint64, shardOffset uint64) error) error { |
Member
There was a problem hiding this comment.
nit: what do you think of using the idiomatic iterator syntax?
We could create a new NodeInIndex type as:
type NodeInIndex struct {
Cid cid.Cid
Size uint64
ShardDigest multihash.Multihash
ShardOffset uint64
and then have this function be:
func (r *Repo) NodesInIndex(ctx context.Context, indexID id.IndexID) iter.Seq2[NodeInIndex, error]
and then the caller can range over the results and do whatever is needed with them.
| } | ||
| var rows []row | ||
| err = repo.ForEachNodeInIndex(t.Context(), index.ID(), func(shardDigest multihash.Multihash, nodeCID cid.Cid, nodeSize uint64, shardOffset uint64) error { | ||
| rows = append(rows, row{shardDigest: shardDigest, nodeCID: nodeCID, nodeSize: nodeSize, shardOffset: shardOffset}) |
Member
There was a problem hiding this comment.
nit: why not build the map here directly instead of adding to a list and then converting that to a map?
Also, to DRY the assertions afterwards, I'd build a map with the expected results indexed by CID and then do the requires here:
nodeInIndex := expectedNodesByCID[nodeCID.String()]
require.Equal(t, nodeInIndex.ShardDigest, []byte(shardDigest))
require.Equal(t, nodeInIndex.Size, nodeSize)
require.Equal(t, nodeInIndex.ShardOffset, shardOffset)
To ensure we are getting the expected 4 nodes, we can add a simple counter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Dependency Tree
This tree was auto-generated by Charcoal