Skip to content

Commit

Permalink
CySQL Fix Poor Type Negotiation for []graph.ID Parameters (#1054)
Browse files Browse the repository at this point in the history
* fix: BED-5255 avoid panic prone caching logic

* fix: BED-5256 fix []uint64 negotiation for parameters
  • Loading branch information
zinic authored Jan 7, 2025
1 parent df1a43c commit a995978
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/go/dawgs/graph/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ func IDsToUint32Slice(ids []ID) []uint32 {
return rawIDs
}

func IDsToUint64Slice(ids []ID) []uint32 {
rawIDs := make([]uint32, len(ids))
func IDsToUint64Slice(ids []ID) []uint64 {
rawIDs := make([]uint64, len(ids))

for idx, id := range ids {
rawIDs[idx] = id.Uint32()
rawIDs[idx] = id.Uint64()
}

return rawIDs
Expand Down
10 changes: 8 additions & 2 deletions packages/go/dawgs/graphcache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,23 @@ func ShallowFetchNodesByID(tx graph.Transaction, cache Cache, ids []graph.ID) ([
cachedNodes, missingNodeIDs := cache.GetNodes(ids)

if len(missingNodeIDs) > 0 {
newNodes := make([]*graph.Node, 0, len(missingNodeIDs))

if err := fetchNodesByIDQuery(tx, missingNodeIDs).FetchKinds(func(cursor graph.Cursor[graph.KindsResult]) error {
for next := range cursor.Chan() {
cachedNodes = append(cachedNodes, graph.NewNode(next.ID, nil, next.Kinds...))
newNodes = append(newNodes, graph.NewNode(next.ID, nil, next.Kinds...))
}

return cursor.Error()
}); err != nil {
return nil, err
}

cache.PutNodes(cachedNodes[len(cachedNodes)-len(missingNodeIDs):])
// Put the fetched nodes into cache
cache.PutNodes(newNodes)

// Append them to the end of the nodes being returned
cachedNodes = append(cachedNodes, newNodes...)
}

return cachedNodes, nil
Expand Down

0 comments on commit a995978

Please sign in to comment.