[gold] Try computing diffs against triaged ignored digests too

The number of triaged, ignored digests is expected to be small,
and some instances (chrome) make use of ignored traces as a
work around to getting many emails for less-well-tested traces.

Bug: skia:10582
Change-Id: I785d82141ed34f42d076ce10c4ee02c238eeb15a
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/372390
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
diff --git a/golden/go/diff/diff.go b/golden/go/diff/diff.go
index 306b8ef..9a7d73b 100644
--- a/golden/go/diff/diff.go
+++ b/golden/go/diff/diff.go
@@ -304,16 +304,16 @@
 type Calculator interface {
 	// CalculateDiffs recomputes all diffs for the current grouping, including any digests provided.
 	// Images (digests) will be sorted into two buckets, the left and right bucket. The left bucket
-	// is a superset of the right bucket. The right bucket consists of "triaged, not ignored" images
+	// is a superset of the right bucket. The right bucket consists of all triaged images
 	// for this grouping. The left bucket consists of *all* digests seen for this grouping.
 	// During search, a user will want to see the closest positive and negative image for a given
 	// image. By splitting the images into two different buckets, we do less precomputation. For
 	// example, if there are several flaky traces in a grouping, it can be that 10% of the overall
-	// images for a grouping are *not* ignored (and are mostly triaged) and 90% are ignored (because
-	// the trace produces something different during most commits). In such a case, computing a
-	// given digest from an ignored trace against a different digest from an ignored trace is a
-	// waste since it won't show up in the search results. By splitting the images into two buckets,
-	// we can dramatically reduce the computation done over a naive N x N comparison scheme.
+	// images for a grouping are triaged and 90% are *not* (these typically come from ignored traces
+	// because they produce something different during most commits). In such a case, computing a
+	// given untriaged digest from a trace against a different untriaged digest is a waste since it
+	// won't show up in the search results. By splitting the images into two buckets, we can
+	// dramatically reduce the computation done over a naive N x N comparison scheme.
 	CalculateDiffs(ctx context.Context, grouping paramtools.Params, additionalLeft, additionalRight []types.Digest) error
 }
 
@@ -335,6 +335,6 @@
 	// AdditionalRight are digests beyond those that have been seen on the primary branch that
 	// should be included in the "right bucket" of diff calculations. It expected that tryjob results
 	// should set these to be non-empty, as well as when running in compatibility mode with the
-	//previous system. The digests in this bucket should be from not-ignored traces.
+	//previous system. The digests in this bucket should be triaged on the primary branch.
 	AdditionalRight []types.Digest `json:"additional_right,omitempty"`
 }
diff --git a/golden/go/indexer/indexer.go b/golden/go/indexer/indexer.go
index 5a5b219..bb5a9f1 100644
--- a/golden/go/indexer/indexer.go
+++ b/golden/go/indexer/indexer.go
@@ -951,14 +951,14 @@
 	return digestsPerGrouping, nil
 }
 
-// addDataFromPrimaryBranch adds the triaged, not ignored digests from the primary branch to
+// addDataFromPrimaryBranch adds the triaged digests from the primary branch to
 // the provided map and returns it as the first return value (the left digests). It adds those same
 // digests to a new map and returns it as the second return value (the right digests).
 func addDataFromPrimaryBranch(ctx context.Context, idx *SearchIndex, leftDigests map[hashableGrouping]types.DigestSet, exp expectations.Classifier) (map[hashableGrouping]types.DigestSet, map[hashableGrouping]types.DigestSet, error) {
 	ctx, span := trace.StartSpan(ctx, "addDataFromPrimaryBranch")
 	span.AddAttributes(trace.Int64Attribute("groupings", int64(len(leftDigests))))
 	defer span.End()
-	countByTest := idx.dCounters[types.ExcludeIgnoredTraces].ByTest()
+	countByTest := idx.dCounters[types.IncludeIgnoredTraces].ByTest()
 	rightDigests := make(map[hashableGrouping]types.DigestSet, len(leftDigests))
 	// Add the digests from the primary branch (using the index)
 	for grouping := range leftDigests {
@@ -1013,13 +1013,13 @@
 	// For every digest on every trace within the sliding window (tile), compute the
 	// unique digests for each grouping (i.e. test). These will be the left digests.
 	leftDigestsPerGrouping := map[hashableGrouping]types.DigestSet{}
-	for _, trace := range tile.Traces {
-		grouping := getHashableGrouping(trace.Keys())
+	for _, tr := range tile.Traces {
+		grouping := getHashableGrouping(tr.Keys())
 		uniqueDigests := leftDigestsPerGrouping[grouping]
 		if len(uniqueDigests) == 0 {
 			uniqueDigests = types.DigestSet{}
 		}
-		for _, d := range trace.Digests {
+		for _, d := range tr.Digests {
 			if d != tiling.MissingDigest {
 				uniqueDigests[d] = true
 			}
@@ -1027,23 +1027,22 @@
 		leftDigestsPerGrouping[grouping] = uniqueDigests
 	}
 
-	tile = idx.cpxTile.GetTile(types.ExcludeIgnoredTraces)
 	exp, err := idx.expectationsStore.Get(ctx)
 	if err != nil {
 		return skerr.Wrap(err)
 	}
 	// For every digest on every trace within the sliding window (tile), compute the
 	// unique digests for each grouping (i.e. test). These will be the right digests, i.e.
-	// all the "triaged" digests.
+	// all the "triaged" digests (including ignored, triaged digests).
 	rightDigestsPerGrouping := map[hashableGrouping]types.DigestSet{}
-	for _, trace := range tile.Traces {
-		grouping := getHashableGrouping(trace.Keys())
+	for _, tr := range tile.Traces {
+		grouping := getHashableGrouping(tr.Keys())
 		uniqueDigests := rightDigestsPerGrouping[grouping]
 		if len(uniqueDigests) == 0 {
 			uniqueDigests = types.DigestSet{}
 		}
-		for _, d := range trace.Digests {
-			if d != tiling.MissingDigest && exp.Classification(trace.TestName(), d) != expectations.Untriaged {
+		for _, d := range tr.Digests {
+			if d != tiling.MissingDigest && exp.Classification(tr.TestName(), d) != expectations.Untriaged {
 				uniqueDigests[d] = true
 			}
 		}