Skip to content

Commit

Permalink
fix(serving): clear empty xref sets after all reads (#5465)
Browse files Browse the repository at this point in the history
This ensures that a soft deadline returns xrefs.
  • Loading branch information
schroederc committed Dec 1, 2022
1 parent d58a2a0 commit 48cd9d0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions kythe/go/serving/xrefs/xrefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ readLoop:
crs = &xpb.CrossReferencesReply_CrossReferenceSet{
Ticket: ticket,
}
reply.CrossReferences[ticket] = crs

// If visiting a non-merge node and facts are requested, add them to the result.
if ticket == cr.SourceTicket && len(patterns) > 0 && cr.SourceNode != nil {
Expand Down Expand Up @@ -983,11 +984,6 @@ readLoop:
}
}

if len(crs.Declaration) > 0 || len(crs.Definition) > 0 || len(crs.Reference) > 0 || len(crs.Caller) > 0 || len(crs.RelatedNode) > 0 {
reply.CrossReferences[crs.Ticket] = crs
tracePrintf(ctx, "CrossReferenceSet: %s", crs.Ticket)
}

for i == len(tickets)-1 && len(indirectionPages) > 0 {
// We've hit the end of known tickets to pull for xrefs; read an
// indirection page until we've found another ticket or we've exhausted
Expand All @@ -1002,12 +998,24 @@ readLoop:
tickets = addMergeNode(mergeInto, tickets, ticket, rn.Node.GetTicket())
}
}

tracePrintf(ctx, "CrossReferenceSet: %s", crs.Ticket)
}
if !foundCrossRefs {
// Short-circuit return; skip any slow requests.
return &xpb.CrossReferencesReply{}, nil
}

var emptySets []string
for key, crs := range reply.CrossReferences {
if len(crs.Declaration)+len(crs.Definition)+len(crs.Reference)+len(crs.Caller)+len(crs.RelatedNode) == 0 {
emptySets = append(emptySets, key)
}
}
for _, k := range emptySets {
delete(reply.CrossReferences, k)
}

if initialSkip+stats.total != sumTotalCrossRefs(reply.Total) && stats.total != 0 {
nextPageToken.Indices["skip"] = int32(initialSkip + stats.total)
}
Expand Down

0 comments on commit 48cd9d0

Please sign in to comment.