serving/xrefs: short-circuit return when no serving data is found
Reviewers: #core_team, zarko
Subscribers: #core_team
@@ -891,6 +891,7 @@ func (t *Table) CrossReferences(ctx context.Context, req *xpb.CrossReferencesReq
req.CallerKind != xpb.CrossReferencesRequest_NO_CALLERS ||
len(req.Filter) > 0)
+ var foundCrossRefs bool
for i := 0; i < len(tickets); i++ {
ticket := tickets[i]
cr, err := t.crossReferences(ctx, ticket)
@@ -900,6 +901,7 @@ func (t *Table) CrossReferences(ctx context.Context, req *xpb.CrossReferencesReq
} else if err != nil {
return nil, fmt.Errorf("error looking up cross-references for ticket %q: %v", ticket, err)
}
+ foundCrossRefs = true
for _, feature := range cr.Feature {
features[feature] = true
}
@@ -1090,6 +1092,10 @@ func (t *Table) CrossReferences(ctx context.Context, req *xpb.CrossReferencesReq
tracePrintf(ctx, "CrossReferenceSet: %s", crs.Ticket)
}
}
+ if !foundCrossRefs {
+ // Short-circuit return; skip any slow requests.
+ return &xpb.CrossReferencesReply{}, nil
+ }
if initialSkip+stats.total != sumTotalCrossRefs(reply.Total) && stats.total != 0 {
nextPageToken.Indices["skip"] = int32(initialSkip + stats.total)
