Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Oct 22, 2024
1 parent 47b9a0d commit b366bff
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions tests/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,19 @@ func createDoc(
startDocIndex := len(s.docIDs[action.CollectionID])
s.docIDs[action.CollectionID] = append(s.docIDs[action.CollectionID], docIDs...)

if action.CollectionID >= len(s.cids) {
// Expand the slice if required, so that the cids can be accessed by collection index
s.cids = append(s.cids, make([][]map[string][]cid.Cid, action.CollectionID+1)...)
}

endDocIndex := startDocIndex + len(docIDs) - 1
if endDocIndex >= len(s.cids[action.CollectionID]) {
s.cids[action.CollectionID] = append(
s.cids[action.CollectionID],
make([]map[string][]cid.Cid, endDocIndex-len(s.cids[action.CollectionID])+1)...,
)
}

for relativeDocIndex, docID := range docIDs {
results, err := nodes[0].Headstore().Query(
s.ctx,
Expand All @@ -1301,26 +1314,16 @@ func createDoc(
s.t.Fatalf("failed to fetch cids: %s", err.Error())
}

if action.CollectionID >= len(s.cids) {
// Expand the slice if required, so that the cids can be accessed by collection index
s.cids = append(s.cids, make([][]map[string][]cid.Cid, action.CollectionID+1)...)
}

colCids := s.cids[action.CollectionID]
docIndex := startDocIndex + relativeDocIndex
if docIndex >= len(colCids) {
colCids = append(colCids, make([]map[string][]cid.Cid, docIndex-len(colCids)+1)...) // todo - this can be moved outside of loop
}

if colCids[docIndex] == nil {
colCids[docIndex] = map[string][]cid.Cid{}
if s.cids[action.CollectionID][docIndex] == nil {
s.cids[action.CollectionID][docIndex] = map[string][]cid.Cid{}
}

// This is a new doc, so we can blindly overwrite the array of cids
colCids[docIndex][key.FieldID] = []cid.Cid{
s.cids[action.CollectionID][docIndex][key.FieldID] = []cid.Cid{
key.Cid,
}
s.cids[action.CollectionID] = colCids
}
}

Expand Down

0 comments on commit b366bff

Please sign in to comment.