1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 14:31:44 +01:00

fix: improves search on initital load (#3253)

This commit is contained in:
Amir Raminfar
2024-09-04 17:22:30 -07:00
committed by GitHub
parent 51a3f1f03b
commit 45c7224d13
2 changed files with 20 additions and 6 deletions

View File

@@ -168,7 +168,7 @@ function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
fetchingInProgress = true;
try {
const stopWatcher = watchOnce(url, () => abortController.abort("stream changed"));
const moreParams = { ...params.value, from: from.toISOString(), to: to.toISOString(), fill: "1" };
const moreParams = { ...params.value, from: from.toISOString(), to: to.toISOString(), minimum: "100" };
const logs = await (
await fetch(withBase(`${loadMoreUrl.value}?${new URLSearchParams(moreParams).toString()}`), { signal })
).text();

View File

@@ -5,6 +5,7 @@ import (
"context"
"errors"
"regexp"
"strconv"
"strings"
"github.com/goccy/go-json"
@@ -117,10 +118,27 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
}
}
minimum := 0
if r.URL.Query().Has("minimum") {
minimum, err = strconv.Atoi(r.URL.Query().Get("minimum"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if minimum < 0 || minimum > buffer.Size {
http.Error(w, errors.New("minimum must be between 0 and buffer size").Error(), http.StatusBadRequest)
return
}
}
for {
if buffer.Len() > 0 {
if buffer.Len() > minimum {
break
}
buffer.Clear()
events, err := containerService.LogsBetweenDates(r.Context(), from, to, stdTypes)
if err != nil {
log.Error().Err(err).Msg("error fetching logs")
@@ -138,10 +156,6 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
}
}
if !r.URL.Query().Has("fill") { // only auto fill if fill query parameter is set
break
}
from = from.Add(-delta)
delta = delta * 2