internal/postgres: apply fixes from prev CL I implemented the reviewer-requested changes in https://go.dev/cl/796720 but did not push. This CL has the changes. Change-Id: I51cdceb0a84f1fbf348dadc6c7cb400723522d90 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/800521 Reviewed-by: Ethan Lee <ethanalee@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Bypass: Jonathan Amsterdam <jba@google.com> Auto-Submit: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/postgres/search.go b/internal/postgres/search.go index 56f87f9..62b8222 100644 --- a/internal/postgres/search.go +++ b/internal/postgres/search.go
@@ -777,16 +777,19 @@ } func computeChangedCounts(ctx context.Context, prefix string, curCounts, newCounts map[string]int) map[string]int { + // Find all counts that have changed, including those that have changed to zero + // because there are no longer any importers in imports_unique. changedCounts := map[string]int{} - for p, nc := range newCounts { - cc, present := curCounts[p] - if present && cc != nc { + for p, cc := range curCounts { + nc := newCounts[p] // nc is 0 if not present in newCounts + if cc != nc { changedCounts[p] = nc } } + pct := 0 - if len(newCounts) > 0 { - pct = len(changedCounts) * 100 / len(newCounts) + if len(curCounts) > 0 { + pct = len(changedCounts) * 100 / len(curCounts) } log.Debugf(ctx, "update-imported-by-counts: %s: %d changed (%d%%)", prefix, len(changedCounts), pct) return changedCounts