Skip to content

Commit e51ff07

Browse files
authored
search: only indicate limit hit if reasons say so (#514)
If we hit the display limit we display the statistics with a "+". This is misleading, since the result count is accurate. So we update the logic to be the same as used in the webapp.
1 parent a6beb12 commit e51ff07

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

cmd/src/search_stream.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ func textDecoder(query string, t *template.Template, w io.Writer) streaming.Deco
9393
if !progress.Done {
9494
return
9595
}
96-
err := t.ExecuteTemplate(w, "progress", progress)
96+
97+
templateData := struct {
98+
streaming.Progress
99+
LimitHit bool
100+
}{
101+
Progress: *progress,
102+
LimitHit: isLimitHit(progress),
103+
}
104+
105+
err := t.ExecuteTemplate(w, "progress", &templateData)
97106
if err != nil {
98107
logError(fmt.Sprintf("error when executing template: %s\n", err))
99108
}
@@ -180,6 +189,17 @@ func textDecoder(query string, t *template.Template, w io.Writer) streaming.Deco
180189
}
181190
}
182191

192+
// isLimitHit returns true if any of the skipped reasons indicate a limit was
193+
// hit. This is the same logic we use in the webapp.
194+
func isLimitHit(progress *streaming.Progress) bool {
195+
for _, p := range progress.Skipped {
196+
if strings.Contains(string(p.Reason), "-limit") {
197+
return true
198+
}
199+
}
200+
return false
201+
}
202+
183203
const streamingTemplate = `
184204
{{define "file"}}
185205
{{- /* Repository and file name */ -}}
@@ -265,7 +285,7 @@ const streamingTemplate = `
265285
{{- else -}}
266286
{{- color "success" -}}
267287
{{- end -}}
268-
{{- .MatchCount -}}{{if len .Skipped}}+{{end}} results{{- color "nc" -}}
288+
{{- .MatchCount -}}{{if .LimitHit}}+{{end}} results{{- color "nc" -}}
269289
{{- " in " -}}{{color "success"}}{{msDuration .DurationMs}}{{if .RepositoriesCount}}{{- color "nc" -}}
270290
{{- " from " -}}{{color "success"}}{{.RepositoriesCount}}{{- " Repositories" -}}{{- color "nc" -}}{{end}}
271291
{{- "\n" -}}

0 commit comments

Comments
 (0)